Sub topic 9
Capture Decisions as Design Tokens and Components
This chapter assumes you have a wireframe, a layout grid with a spacing scale, a type scale, and a color palette from the earlier chapters. It also assumes you can use a design tool such as Figma and read basic CSS. The goal here is to turn those decisions into a small, named set of values and reusable pieces. The high-fidelity mockup in the next chapter is then built from those pieces and not from one-off choices.
What a design token is
A design token is a named value that stands for a design decision. Instead of writing #0b5fff in forty places, you write color-accent and define it once. The name carries the intent. The value can change later without hunting through every screen.
Tokens give you three things:
- Consistency. Every button uses the same blue because every button points at the same token.
- Cheap change. If the brand blue shifts, you edit one value.
- A shared vocabulary. Designers and developers use the same names, so "use space-3 above the heading" means the same thing to both.
A token is not a style applied to one element. A token is a value. A style or component then uses that value.
Primitive tokens and semantic tokens
Most teams keep two layers of tokens, and mixing them up is a common error.
- Primitive tokens describe what the value is:
blue-600,gray-900,space-3. - Semantic tokens describe what the value is for:
color-accent,color-text,color-bg.
Components should use semantic tokens. A semantic token points at a primitive, so you can retarget it in one place.
| Layer | Example name | Example value | Used by |
|---|---|---|---|
| Primitive | `blue-600` | `#0b5fff` | Semantic tokens only |
| Semantic | `color-accent` | `blue-600` | Buttons, links, highlights |
| Semantic | `color-text` | `gray-900` | Body copy, headings |
| Component | `button-bg` | `color-accent` | The button component |
The third layer, component tokens, is optional. For a single homepage, primitives plus semantic tokens are usually enough. Add component tokens only when one component needs to vary from the shared meaning.
From decisions to tokens
Walk back through the earlier chapters and collect every decision that repeats.
- Spacing. Your spacing scale becomes
space-1throughspace-4. Use the scale's steps and avoid in-between values. - Type. Each step of the type scale becomes a size token:
font-size-body,font-size-h2,font-size-h1. Line height and weight can be tokens too. - Color. Keep the palette small. Text, background, and accent cover most of a homepage. Add a muted text color and a border color if the mockup needs them.
- Layout. Record the content max width, the gutter, and the breakpoint values.
Here is the homepage's decisions written as CSS custom properties. This is the same information a design tool shows in its variables panel, written in the form a developer will use.
:root {
--space-1: 0.5rem;
--space-2: 1rem;
--space-3: 1.5rem;
--space-4: 2.5rem;
--color-text: #1a1a1a;
--color-bg: #ffffff;
--color-accent: #0b5fff;
--font-size-body: 1rem;
--font-size-h2: 1.75rem;
--font-size-h1: 2.5rem;
}
body {
color: var(--color-text);
background: var(--color-bg);
font-size: var(--font-size-body);
}
h1 { font-size: var(--font-size-h1); }
h2 { font-size: var(--font-size-h2); }Each rule reads a token with var(...). Change --color-accent once and every rule that reads it follows. Note that rem units scale with the user's browser font setting, which helps readers who enlarge their text.
Tokens in the design tool
You do not need code to use tokens. In Figma, the same idea appears as variables and styles. Create a color variable collection, a number collection for spacing, and text styles for the type scale. Then apply them instead of typing raw values.
A good check is to select any layer and look at its fill. If it shows a variable name, it is tokenized. If it shows a raw hex code, it is a stray value. Strays are how a design drifts: one slightly different gray here, a 17px gap there.
From elements to components
A component is a reusable piece of the interface built from tokens, with a defined set of variations. Where a token captures one value, a component captures a whole unit: a button, a feature card, a nav link.
Look at your wireframe and find anything that appears more than once or that has more than one state. On a typical homepage that gives you:
- Button with primary and secondary variants, plus hover, focus, and disabled states.
- Feature card repeated three or more times in the features section.
- Testimonial repeated in the proof section.
- Navigation link used in the header and the footer.
- Section heading with a consistent gap below it.
The wireframe's repeated blocks are the best guide. If you drew the same box three times, it is a component.
Variants and states
A component should list its variants (intentional differences, such as primary versus secondary) and its states (temporary conditions, such as hover or focus). Design every state now. The focus state matters most, because keyboard users depend on it, and a mockup that skips it leaves developers to guess.
| Component | Variants | States to design |
|---|---|---|
| Button | Primary, secondary | Default, hover, focus, active, disabled |
| Feature card | With icon, with image | Default, hover (if linked) |
| Nav link | Standard, current page | Default, hover, focus |
| Text input | Single line | Default, focus, error, disabled |
How components use tokens
A component should contain no raw values. Here is the button written so every value comes from a token. This assumes the :root block above is loaded.
.button {
display: inline-block;
padding: var(--space-1) var(--space-3);
background: var(--color-accent);
color: var(--color-bg);
font-size: var(--font-size-body);
text-decoration: none;
border-radius: 0.25rem;
}
.button:focus-visible {
outline: 3px solid var(--color-text);
outline-offset: 2px;
}The border-radius here is a raw value. That is a gap worth noticing: if you round corners on cards, inputs, and buttons, the radius should become a token such as --radius-1 too. Finding gaps like this is part of the process.
The relationship between tokens and components
The flow is one-directional. Primitives feed semantic tokens, semantic tokens feed components, and components feed the page.
Because the arrows run one way, an edit at the top propagates downward without surprises. A component should never reach back and redefine a primitive.
Edge cases and common errors
Too many tokens. Creating space-1 through space-14 defeats the point. A small scale forces decisions. If you cannot choose between two near values, drop one.
Tokens named by value. space-16 for 16 pixels breaks when the value changes. Use ordinal steps like space-2, or role names.
Raw values hiding in components. The border radius above is one case. Shadows, border widths, and transition durations often slip through. Audit them before handoff.
Over-componentizing. Not every box needs to be a component. A one-time hero layout can stay a plain frame. Make a component when something repeats or has states.
Variants that multiply. A button with size, color, icon, and width options can reach dozens of combinations. Limit variants to those the homepage uses.
Dark mode or themes. If you later need a second theme, semantic tokens make it possible: you redefine color-bg and color-text for the theme and components follow. This only works if components never used the primitive directly.
Checking your set
Before moving to the mockup, run a short audit:
- Every color in the file comes from a color token.
- Every gap and padding value comes from the spacing scale.
- Every text layer uses a defined text style.
- Every repeated block is a component, and each component has its states designed.
- Names describe purpose, and no two tokens hold the same job.
Passing this audit means the high-fidelity mockup can be assembled quickly and will stay consistent. It also means the developer handoff, covered in a later chapter, is mostly a matter of exporting names that already exist.
Exercise
Your homepage uses the color #0b5fff for the primary button, link text, and a highlight bar. A teammate proposes naming the token color-blue. The brand team later announces the accent will change to green. Explain why color-accent is the better name, and say which layer (primitive or semantic) each of blue-600 and color-accent belongs to.
Show answer
color-accent names the purpose, so it stays accurate after the change from blue to green. color-blue would then hold a green value, which is misleading. blue-600 is a primitive token because it describes what the value is. color-accent is a semantic token because it describes what the value is for. Components should use color-accent, which points at a primitive that can be swapped in one place.
Exercise
Look at this CSS for a feature card: .card { padding: 20px; background: #f4f6fa; border-radius: 8px; }. Name two problems from a token point of view and describe how to fix them.
Show answer
The values are raw: 20px is not on the spacing scale and #f4f6fa and 8px are not tokens. Fix it by using a spacing token such as var(--space-2) or var(--space-3) for the padding, adding a semantic color token such as --color-surface for the background, and adding a --radius-1 token for the corners. If 20px was chosen deliberately, either add it to the scale as a named step or move to the nearest existing step.