Design tokens
Three tiers
| Tier | Example | Used by |
|---|---|---|
| Primitive (raw palette and scales) | color.blue.600 = #2563eb, space.4 = 1rem |
Only semantic tokens |
| Semantic (meaning) | color.text.default, color.action.primary, space.inset.m |
Components |
| Component (optional) | button.primary.background |
One component |
Components should reference semantic tokens, never primitives. Theming (dark mode, brands) then means remapping semantic tokens only.
Format (DTCG)
The W3C Design Tokens Community Group published the first stable Design Tokens Format Module (2025.10). Tokens are JSON objects with $value and optionally $type and $description; groups are nested objects; references use {group.token}; $type set on a group is inherited.
{
"color": {
"$type": "color",
"blue": { "600": { "$value": "#2563eb" } },
"text": { "default": { "$value": "{color.gray.900}", "$description": "Body text" } }
},
"space": { "$type": "dimension", "4": { "$value": "1rem" } }
}
The 2025.10 format also allows structured values (for example a color as an object with colorSpace and components, a dimension as { "value": 16, "unit": "px" }); the bundled converter handles the common string forms and simple dimension objects. For full spec coverage use a dedicated tool such as Style Dictionary or Terrazzo.
Generate CSS variables
python3 scripts/tokens_to_css.py tokens.json > tokens.css
python3 scripts/tokens_to_css.py tokens.json --theme dark=tokens.dark.json > tokens.css
python3 scripts/tokens_to_css.py tokens.json --prefix ds
Output: :root { --color-blue-600: #2563eb; --color-text-default: var(--color-gray-900); ... }. References become var(...) so themes cascade. A dark theme file only needs the tokens it overrides; it is emitted under [data-theme="dark"] and inside @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { ... } }. Errors on unknown references and reference cycles.
Rules
- Name by role, not by value:
color.text.muted, notcolor.gray-light. - Keep scales small and consistent (a 4 px or 8 px spacing base; a modular type scale).
- Check contrast of every semantic text/background pair in every theme (use
color-contrast). - When replacing hard-coded values, search for every literal (
#2563eb,16px) and map it to the closest semantic token; flag values with no good token instead of inventing one-off tokens. - Treat tokens as an API: deprecate (keep old name pointing to new) before removing.