
Design Tokens as CSS Custom Properties
How design tokens land as CSS custom properties: scope and inheritance make theming a value swap, while unregistered, untyped properties fail silently. What to watch at runtime.
TL;DR: When a token build targets CSS, design tokens land as CSS custom properties — declarations the build emits onto a root or a scope, where a semantic property can reference a primitive one through var() and preserve the tier chain at runtime. Scope and inheritance are what make theming a value swap on an element rather than a per-element edit. The catch is that unregistered custom properties are not type-checked and fail silently. A missing value uses the var() fallback when there is one; without one, or when the substituted value is invalid for the property, a regular CSS property behaves as unset — the inherited value for inherited properties such as color, the initial value otherwise. The cascade that gives you the power also lets you lose track of where a value came from.
From token output to custom property
The token build emits, among its outputs, a set of CSS custom property declarations. These are name-value pairs written onto a selector — commonly :root for the global set, or a narrower scope for a subset. Once declared, any stylesheet or component can read them with var() on elements inside the scope where they are declared. The build produces the declarations; the browser consumes them. How the build gets from source to these declarations is the build pipeline's concern, not this one — here the starting point is the emitted custom properties themselves.
What makes custom properties fit tokens so well is that one custom property can reference another through var(). A semantic property can point at a primitive property, and the reference resolves at runtime rather than being flattened at build time. That preserves the tier chain live in the browser: --color-text-default refers to a specific gray, and if you change that gray on the element where --color-text-default is declared (here :root), everything referring to --color-text-default updates without a rebuild.
/* Emitted by the build — the tier chain preserved as var() references. */
:root {
--color-neutral-900: #111827; /* primitive */
--color-text-default: var(--color-neutral-900); /* semantic -> primitive */
}
.card-title {
color: var(--color-text-default); /* component consumes the semantic role */
}The naming convention and the tier model behind these names — why there is a primitive layer and a semantic layer at all — are their own subject. What matters here is the runtime property: MDN's reference on custom properties documents it and cites the specification that defines it, the W3C CSS Custom Properties for Cascading Variables Module Level 1; the shape above is how a token set inhabits it.
Scope is the runtime superpower
Unregistered custom properties are inherited properties that cascade like any other CSS property (one registered with @property and inherits: false does not inherit), and that is not a footnote — it is the feature the whole runtime theming story rests on. Because a custom property set on an ancestor is visible to its descendants, you can change a value on a scope and every element beneath it that reads that property re-resolves, without touching any of those elements individually.
This is what makes a theme a value swap. Set the theme's values for the semantic properties on a scope — the document root, a section, a single subtree — and every component inside that scope picks up the new values through the properties it already consumes. You do not edit each component; you set the properties once on the scope and inheritance carries them down. Applying a theme becomes a matter of writing a value set onto a selector.
/* A scope re-resolves everything beneath it — no per-element edits. */
[data-theme="dark"] {
--color-text-default: var(--color-neutral-50);
}
/* A component can also scope its own override without touching globals. */
.promo-panel {
--color-text-default: var(--color-blue-100);
}The same mechanism gives you component-scoped overrides. Set a custom property on a component's own root and it applies within that component and nowhere else — the global value is untouched, and only this subtree sees the override. This is why runtime theming works without rebuilding: the values live in the cascade, and changing a property on a scope changes what every var() reading that property beneath it resolves to. A semantic property declared on :root keeps the primitive value it resolved there, which is why the example above redeclares --color-text-default on the theme scope rather than changing only the primitive it points to. The strategic question of which theme values to design — light, dark, brand — is covered in the article on theming; the runtime capability that makes those swaps possible is scope and inheritance.
Runtime versus build-time theming
There are two ways to deliver a theme, and custom properties are what make the runtime path viable. Build-time theming ships one stylesheet per theme: the values are baked in, and the application loads the light sheet or the dark sheet. Runtime theming ships one set of components and swaps the custom property values on a scope live, so the same components re-resolve to new values in place. The choice between these is a theming-strategy decision and is deferred to that article; the runtime path is the one custom properties enable directly.
The runtime path introduces two things to handle. The first is fallbacks. var() accepts a second argument used when the named property has no usable value — for an unregistered property, when it is not set, is set to initial, or is invalid at computed-value time (for example, through a dependency cycle): var(--color-text-default, #111827) renders the fallback if --color-text-default is missing. MDN's var() reference describes exactly when the fallback applies — notably that it covers an unset property, not every kind of invalid value, which is a distinction the next section returns to.
The second is the flash of the wrong theme. If the page paints before the theme scope is set, the user sees the default values briefly, then a jump to the intended theme. The fix is ordering: set the scope's values before first paint so the correct theme is present when the browser paints, rather than applied a beat later. This is a runtime concern that lives with the theming runtime, flagged here as a direct consequence of theming through the cascade.
Failure modes specific to custom properties
Custom properties fail differently from ordinary CSS, and the differences are mostly silent. The table below summarizes four of them and why each is easy to miss.
| Failure mode | What happens | Why it is easy to miss |
|---|---|---|
| Property unset | `var()` uses its fallback; with none, a regular CSS property behaves as `unset` (inherited value for inherited properties, initial value otherwise) | No error; the element just looks slightly wrong |
| Invalid computed value | A regular CSS property behaves as `unset` — inherited value for inherited properties, initial value otherwise | Renders as if unstyled, with no console signal |
| Wrong value type | A length where a color is expected is invalid at computed-value time, so `color` takes its inherited value | The browser does not type-check unregistered custom properties; nothing warns you |
| Deep reference chain | The value resolves, but through several `var()` hops | The rendered value is correct; its origin is hard to trace |
The root cause of the second and third rows is that the browser does not type-check unregistered custom properties. An unregistered custom property holds an arbitrary token sequence until it is used, and only at use is it interpreted. Put a px value where a color is expected and the declaration does not throw — it is invalid at computed-value time, so color takes its inherited value (a non-inherited property such as background-color takes its initial value), and any earlier rule for that property is not used either. The result is not what you intended and looks like a styling bug with no error to grep for. These are silent until someone inspects the computed styles and notices the value is not what the token said.
The last row is the honest limit. The cascade is what gives custom properties their power — set a value high, inherit it everywhere, override it locally — and it is also what lets you lose the thread. A resolved value might come from the root, or a theme scope, or a component override, or a fallback three var() hops deep, and the rendered result looks identical regardless of which. When a color is wrong, tracing which scope actually supplied it means walking the cascade. The power and the traceability cost are the same feature seen from two sides, and knowing that is what keeps the cascade an asset rather than a mystery.