CSS variables reference
11 August 2024 (Updated 18 May 2025)
On this page
Recipes
Define a global variable
:root {
--primary: blue;
}
Use a variable
Without a fallback:
.some-component {
color: var(--primary);
}
With a fallback:
.some-component {
color: var(--primary, pink);
}
Other notes
- Variables can be overridden at a selector level in which case the override cascades downwards for all children elements too.
Tagged:
CSS