The ability to define variables in CSS and then use those variables in multiple places
Native CSS Variables === CSS Custom Properties
:root {
--primary-color: white;
--secondary-color: black;
}
:root {
--primary-color: white;
--secondary-color: black;
}
article {
color: var(--secondary-color);
background-color: var(--primary-color);
}
<selector> {
--<descriptive-name>: <value>;
}
with the var() function
var(--<variable name> [, <default value> ])
why use preprocessor variables
?
1. browser support
why use native CSS custom properties
?
browser support
?
:root {
--color: red;
}
div {
color: var(--color);
}
:root {
--color: red;
}
div {
color: red;
color: var(--color);
}
before
after