CSS custom properties let you define a value once in :root and reference it across every rule in your stylesheet. Changes propagate everywhere the token is used, which makes theme updates and refactors much faster than find-and-replace. This lesson walks through defining tokens, using them with var(), overriding them by scope to create alternate themes, and providing fallback values when a token may be absent.

What this covers

  • Defining shared design tokens in :root
  • Referencing tokens with var(--token-name) in any declaration
  • Scoping overrides on a wrapper class to create alternate themes without rewriting component CSS
  • var(--token, fallback) syntax for safe defaults when a token is missing

CSS variables specimen

Preview