Favorites

CSS custom-properties Property

custom-properties
CSS PropertyThis property is supported by all modern browsers.
Updated 22nd November 2026

Custom properties (CSS variables), such as --main-color, store values you can reuse throughout a style sheet with var().

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

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

The border, background and button all use var(--accent) and var(--radius).
Demo Code
HTML Code
<div class="demo-element">
	The border, background and button all use <code>var(--accent)</code> and <code>var(--radius)</code>.<br>
	<button type="button">Button</button>
</div>
CSS Code
.demo-element {
	width: 240px;
	padding: 16px;
	border: 4px solid var(--accent);
	border-radius: var(--radius);
	background: color-mix(in srgb, var(--accent) 15%, white);
	color: #1b1f3b;
	font-size: 15px;
}
.demo-element button {
	margin-top: 10px;
	padding: 6px 14px;
	border: 0;
	border-radius: var(--radius);
	background: var(--accent);
	color: #fff;
}
.demo-element {
	--radius: 12px;
	--accent: #f72585;
}

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

<div class="card">
<h3>Default card</h3>
<p>Uses the variables defined on :root.</p>
</div>
<div class="card warning">
<h3>Warning card</h3>
<p>Overrides --brand and --radius locally.</p>
</div>
:root {
  --brand: #4361ee;
  --radius: 12px;
  --space: 16px;
}

.card {
  padding: var(--space);
  border: 2px solid var(--brand);
  border-radius: var(--radius);
  margin-bottom: var(--space);
  font-family: system-ui, sans-serif;
}

/* Override the variables for one variant only */
.card.warning {
  --brand: #f72585;
  --radius: 0;
}

.card h3 {
  margin: 0 0 8px;
  color: var(--brand);
}
Open in editor

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.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee