CSS custom-properties Property
Custom properties (CSS variables), such as --main-color, store values you can reuse throughout a style sheet with var().
Description
Custom properties (often called CSS variables) are properties whose names start with two dashes, such as --brand-color or --space-m. They hold a value that can be reused anywhere in the stylesheet with the var() function, for example color: var(--brand-color). Changing the custom property in one place updates every declaration that uses it.
Unlike preprocessor variables, custom properties are real properties that take part in the cascade. They inherit by default, so a value set on :root is available to the whole document, and a value set on a component overrides it for that component's descendants only. They can also be changed by media queries, container queries, pseudo-classes such as :hover, or JavaScript with element.style.setProperty('--x', '10px').
Names are case-sensitive (--Color and --color are different properties). The value can be almost any sequence of tokens and is not checked until it is used through var(). If the substituted value is invalid for the property it lands in, that property becomes "invalid at computed-value time" and falls back to its inherited or initial value. A fallback can be supplied as the second argument of var(): var(--gap, 1rem).
By default custom properties cannot be animated smoothly, because the browser does not know their type. Registering them with the @property at-rule (or CSS.registerProperty()) gives them a syntax, an initial value and an inheritance setting, which makes them animatable and type-checked.
Definition
- Initial value
- see prose (guaranteed-invalid value when not set)
- Applies to
- all elements
- Inherited
- yes
- Computed value
- as specified, with variables substituted
- Animatable
- no (yes when registered with @property)
- JavaScript syntax
- object.style.setProperty()
Interactive Demo
var(--accent) and var(--radius).Syntax
--custom-name: <declaration-value>;
Values
- <declaration-value>Any sequence of one or more tokens, for example a color, a length, a list of values or even a partial value. The value is stored as written and only interpreted when it is substituted with
var(). - initialSets the property to its initial value.
- inheritTakes the computed value of the parent element.
Example
Browser Support
The following information will show you the current browser support for the CSS custom-properties property. Hover over a browser icon to see the version that first introduced support for this CSS property.
Desktop





Tablets & Mobile





