Skip to the content.

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