Overview

A custom property is any property whose name starts with --, read with var(--name, fallback). Define design tokens on :root and override them per theme or component, so dark mode is a variable swap rather than a second stylesheet.

Rules

  • Custom properties inherit and cascade like ordinary properties (cascade), and resolve at computed-value time. Changing one at runtime (a media query, a container query, or element.style.setProperty) updates every var() use, which Sass variables cannot do.
  • Values are untyped by default. Register a property with @property to get a type and make it animatable; syntax and inherits are required, and initial-value is required unless syntax is "*". @property has been available in all major browsers since July 2024.
  • @container style(--x: y) queries read custom property values (container-query).
  • Tailwind 4 emits its theme tokens as CSS variables (tailwind-theme).
:root { --color-bg: #fff; --color-text: #111; }
@media (prefers-color-scheme: dark) { :root { --color-bg: #111; --color-text: #fff; } }
.card { background: var(--color-bg); color: var(--color-text); }