- In CSS, you can define custom variables to set values.
- These variable names start with two hyphens, for example,
--primary-color
. - The variable can then be used in stylesheets by referring to its name.
- When the variable value is changed, all styles using that variable will update accordingly.
- Variables can be defined within a specific element and used by all items nested within.
- To use a variable in CSS, the
var()
function is employed. - As an example, setting the variable
--primary-color
toblue
allows it to be used as a value for text color usingcolor: var(--primary-color);
for anh1
selector. - This results in elements, like a page title, displaying in the color blue as defined by the variable.