CSS Custom Properties: The Decisions That Matter
Variables defined in CSS, such as --brand-color, that can be reused across a stylesheet and changed at runtime, often used to implement design tokens and themes.
On this page
The key figures
- Syntax
- declared with two hyphens and read with var()
- Inheritance
- custom properties inherit like other CSS properties
- Fallbacks
- var() accepts a fallback value
- @property
- registers a custom property with a type, initial value and inheritance
Why this is worth getting right
They let a site change colors, spacing and themes in one place, and unlike preprocessor variables they can be updated live by CSS or JavaScript.
Do this, not that
Do
- Define design tokens as custom properties at the root
- Override them in scopes for themes and components
- Provide fallbacks for critical values
- Name properties by purpose rather than appearance
- Document the available properties in the design system
Don’t
- Hundreds of one-off properties with unclear names
- Using custom properties for values that never change or repeat
- Relying on JavaScript to set values CSS could handle
- Circular references between properties
When to bring in help
Our advice Bring in help when implementing theming or dark mode, or when a stylesheet has grown into repeated hard-coded values.
Where this comes from
- MDN Web Docs — Using CSS custom properties
- MDN Web Docs — @property
The figures and practices above come from the sources listed.
Working on something like this?
We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.
Where to go next
Spotted something wrong? Report an error on this page. We correct on the page and say what changed.