Sub topic 3
Naming values once with design tokens
What a design token is and what you assume
A design token is a named value that stands in for a raw design decision, such as a color, a spacing step, or a corner radius. Instead of writing #1f5fd1 in twenty places, you write color.brand.primary and define the value once.
This chapter assumes you can work with styles, variables, and components in a design tool such as Figma, Sketch, or Adobe XD. It also assumes you know basic CSS, including custom properties (variables written as --name). The previous chapter covered what a handoff contains. This chapter covers how to give each value a stable name that designers and developers both use.
Why tokens belong in a handoff
Without tokens, a spec reads like "padding 16, color blue, radius 6". The developer has to guess whether 16 is a deliberate step in the scale or an accident. They also have to guess whether two similar blues are the same color. Tokens remove that guessing.
Tokens help in four ways:
- One source of truth. Changing
color.brand.primaryonce updates every place that uses it. - A shared vocabulary. A designer can write "space-3" in a spec, and the developer finds
--space-3in the code. - Fewer near-duplicates. A fixed set of values discourages
#1f5fd1,#1e60d0, and#2060d2from coexisting. - Easier review. A reviewer can check that every value in a design is a token, and flag the ones that are not.
Anatomy of a token
Each token has three parts.
| Part | Meaning | Example |
|---|---|---|
| Name | The stable identifier both sides use | `color.brand.primary` |
| Value | The raw value it resolves to | `#1f5fd1` |
| Category | The kind of value, which decides where it may be used | color, space, radius |
Names are organized as a path. Dots separate levels in the design file and in the token file. Hyphens join words inside one level, as in primary-hover. In CSS, the whole path becomes one name joined by hyphens.
A small token file
The following JSON file defines colors, spacing steps, and a radius. The value key follows the convention used by Style Dictionary, a common tool that reads token files and generates code for several platforms. The W3C Design Tokens format uses $value instead, so match whichever one your tooling expects.
{
"color": {
"brand": {
"primary": { "value": "#1f5fd1" },
"primary-hover": { "value": "#174aa6" }
},
"text": {
"default": { "value": "#1a1a1a" },
"disabled": { "value": "#8a8a8a" }
}
},
"space": {
"2": { "value": "8px" },
"3": { "value": "16px" },
"4": { "value": "24px" }
},
"radius": {
"md": { "value": "6px" }
}
}Notice that the space tokens use numbers, not words like "small" and "large". Numbered steps leave room to insert a new step later without renaming everything. They also avoid arguments about whether 16px is "medium" or "large".
From tokens to CSS
Tokens become CSS custom properties. The path color.brand.primary turns into --color-brand-primary.
:root {
--color-brand-primary: #1f5fd1;
--color-brand-primary-hover: #174aa6;
--color-text-disabled: #8a8a8a;
--space-2: 8px;
--space-3: 16px;
--radius-md: 6px;
}
.button {
padding: var(--space-2) var(--space-3);
border: 0;
border-radius: var(--radius-md);
background: var(--color-brand-primary);
color: #fff;
}A spec that says "button padding: space-2 vertical, space-3 horizontal" now maps directly to the padding line. No one has to convert 8px and 16px back into names.
The color: #fff line is a raw value. It is a gap in the token set. A complete file would include a token such as color.text.on-brand and use it here. Raw values left in component code are the most common sign that the token set is incomplete.
Two tiers: primitive and semantic tokens
The small file above mixes two ideas. Some names describe what a value is, and others describe what it is for. Larger systems separate these into tiers.
- Primitive tokens hold raw values and are named by what they are, such as
color.blue.600with the value#1f5fd1. - Semantic tokens are named by purpose and point to a primitive, such as
color.action.primarypointing tocolor.blue.600.
Components use only semantic tokens. If the brand color changes, you repoint one semantic token and no component changes. If you add a dark theme, you give the same semantic names different primitives.
{
"color": {
"blue": {
"600": { "value": "#1f5fd1" },
"700": { "value": "#174aa6" }
},
"action": {
"primary": { "value": "{color.blue.600}" },
"primary-hover": { "value": "{color.blue.700}" }
}
}
}The curly braces are a reference to another token. Style Dictionary and the W3C format both support this idea, but check the exact syntax your tooling accepts.
| Tier | Named by | Used in components? | Example |
|---|---|---|---|
| Primitive | What it is | No | `color.blue.600` |
| Semantic | What it is for | Yes | `color.action.primary` |
A small project can skip the primitive tier. Add it when you need a second theme or when the same color serves several purposes.
Naming rules that hold up
Good names survive redesigns. Use these rules when you create tokens.
- Name by role, not by appearance.
color.text.disabledstays correct if the gray changes.color.light-graybecomes wrong if the value turns into a darker gray. - Use one pattern. Pick an order such as category, group, name, state, and keep it. For example,
color.brand.primary-hoverfollows category, group, name-state. - Use lowercase and hyphens. This avoids case-sensitivity problems and translates cleanly to CSS.
- Avoid abbreviations people must decode. Write
background, notbg, unless your team has agreed on it. - Do not encode the value in the name.
space.16breaks when the step changes to 18px.space.3does not.
Mapping tokens in the design file
In the design tool, tokens usually appear as variables (Figma) or shared styles. The names in the design file must match the names in the token file. If a designer's variable is called Brand/Primary and the code token is color.brand.primary, the mapping still works, but only if both sides agree on the rule that converts one to the other. Write that rule down in the handoff.
A practical checklist for the design file:
- Every fill, stroke, text color, spacing value, and radius uses a variable or style, not a typed-in value.
- Variable names follow the same path structure as the token file.
- Each variable has a short description when its purpose is not obvious, for example "Use for body text on white backgrounds only".
- Unused or experimental variables are removed or placed in a clearly marked group.
Tokens for states
Interactive states often need their own tokens. The hover color of a button is a separate decision from its resting color, so it gets its own name. Chapter-level coverage of states comes later, but the token side is simple: name a state value after the base value plus the state, as in primary-hover.
.button:hover {
background: var(--color-brand-primary-hover);
}
.button:focus-visible {
outline: 2px solid var(--color-brand-primary);
outline-offset: 2px;
}
.button:disabled {
background: transparent;
color: var(--color-text-disabled);
cursor: not-allowed;
}Each state uses a token, so the whole button follows the palette when the palette changes.
Common errors and edge cases
- Raw values in specs. A note that says "#1f5fd1" instead of "color.brand.primary" sends the developer back to guessing. Always cite the token name, and add the raw value in parentheses only as a convenience.
- Tokens that drift. The design file says 8px and the code says 10px. Pick one source of truth, usually the token file, and generate the other side from it or check against it.
- Too many tokens. A token for every one-off value defeats the purpose. If a value is used once and will not be reused, a token may not be worth creating. Ask whether a second use is likely.
- Too few tokens. If designers must type values by hand, they will. Cover the common categories: color, typography, space, radius, shadow, and border width.
- Names tied to a theme.
color.dark-blue-buttonfails when a light theme arrives. Usecolor.action.primary. - Missing contrast checks. A token pair such as text and background can be valid in isolation and fail contrast together. Record which pairs are approved.
- Units left unstated. Say whether spacing is in px or rem. Rem values scale with the user's font-size setting, and px values do not. Choose deliberately and state it.
What to put in the handoff
For tokens, a handoff should include:
- The token file, or a link to its location in the repository.
- A short naming guide that states the pattern and the mapping from design-file names to code names.
- A list of any values in the design that are intentionally not tokens, with the reason.
- The units used for each category.
Exercise
A designer's spec for a card says "background #ffffff, padding 24px, radius 6px, title color #1a1a1a". Rewrite the spec using the tokens from this chapter, and name one value that still needs a new token.
Show answer
Padding 24px is space-4 and radius 6px is radius-md. The title color #1a1a1a is color.text.default. White (#ffffff) has no token in the file, so it needs a new one, for example color.surface.default. Writing the spec this way lets the developer use var(--space-4), var(--radius-md), and var(--color-text-default) without converting any raw values.
Exercise
A team names its tokens color.light-gray and space.16. Explain why each name will cause trouble, and propose a replacement for each.
Show answer
color.light-gray describes appearance, so it becomes wrong if the value changes to a darker gray or if a dark theme reuses it. A role-based name such as color.border.subtle stays correct. space.16 encodes the value, so changing the step to 18px leaves a misleading name. A numbered step such as space.3 does not depend on the pixel value.
Exercise
Why should components use semantic tokens rather than primitive tokens, and what is the benefit when you add a dark theme?
Show answer
Semantic tokens are named by purpose, such as color.action.primary, and point to a primitive. Components that use only semantic names do not need edits when the underlying color changes. For a dark theme, you define the same semantic names with different primitive values, and every component updates without code changes.