open atlas
↑ Back to track
Frontend Architecture FE · 04 · 09

Design tokens: code and config reading

Read real CSS, DTCG JSON, and a theme override; predict how the cascade resolves each token and pick the fix that keeps components theme-agnostic.

FE Senior ◷ 14 min
Level
FoundationsJuniorMiddleSenior

Token bugs live in the CSS and the JSON, not the design doc. Read each snippet, trace how the cascade or the build resolves it, and choose the fix a senior would make first.

Goal

Practise reading token code the way you debug it: follow a reference through its tiers, predict what a theme override re-resolves, and spot the one line that locks a component out of theming.

Snippet 1 — the tier reference

:root {
  --color-blue-600: #0052CC;                  /* primitive */
  --color-interactive: var(--color-blue-600); /* semantic  */
}

.button { background: var(--color-blue-600); }
.link   { color: var(--color-interactive); }
Quiz

A dark theme later redefines --color-interactive (not the primitive). After that, which element follows dark mode, and what is the fix for the other?

Snippet 2 — the DTCG source

{
  "color": {
    "blue": { "600": { "$value": "#0052CC", "$type": "color" } },
    "interactive": { "$value": "{color.blue.600}", "$type": "color" }
  },
  "space": {
    "4": { "$value": "16px", "$type": "dimension" }
  }
}
Quiz

Style Dictionary builds this DTCG source for web and Android. What is true about how color.interactive and space.4 emerge per platform?

Snippet 3 — the theme override

:root              { --color-surface: #FFFFFF; --color-text: #111111; }
[data-theme="dark"]{ --color-surface: #0B0B0F; --color-text: #F5F5F5; }

.card {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid #E5E7EB;   /* hardcoded */
}
Quiz

Toggling data-theme to dark recolors most of .card but leaves one visible defect. What is it and the fix?

Snippet 4 — the fallback

.badge {
  /* --brand-accent is set by some host pages, missing on others */
  color: var(--brand-accent);
  padding: var(--space-2, 8px);
}
Quiz

On a host page that never defines --brand-accent, how does each property behave, and what does the var() fallback teach?

Recap

Token bugs are read in the CSS and the JSON: a component that names a primitive falls out of theming while its semantic-referencing sibling recolors; the DTCG build resolves aliases then transforms values so one source is correct per platform; a single hardcoded literal survives a theme toggle as a visible two-tone defect; and var() with a fallback is the seatbelt for tokens a consumer might not define. Now when you open DevTools and see a color that didn’t follow a theme switch, your first question is “which tier did this rule reference?” — and the trace from there to the fix takes thirty seconds.

Something unclear?

Ask a question about this lesson. Questions are anonymous and go straight to the author to make the lesson better.

shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources2
expand
  1. 01
  2. 02

Trademarks belong to their respective owners. Editorial reference only.