Sub topic 3
Naming values once with design tokens
This chapter assumes you can build frames and components in a design tool and read basic CSS. It covers how to turn the raw values in a design into named tokens that designers and developers share.
What a design token is
A design token is a named value that stands for a design decision. Instead of writing #1f5fd1 in twenty places, you write color.brand.primary once and refer to it everywhere. If the brand blue changes, you edit one line.
Tokens matter in a handoff because they remove guessing. A spec that says "padding 16px" makes the developer decide whether 16 is a special case or part of a system. A spec that says space-3 points to a value that already exists in code.
Choose what becomes a token
Not every number deserves a name. Start with values that repeat or carry meaning:
- Colors: brand, text, background, border, and status colors.
- Spacing: the steps you use for padding, margins, and gaps.
- Radii: corner rounding for buttons, cards, and inputs.
- Type: font families, sizes, weights, and line heights (covered in a later chapter).
A one-off value, such as an illustration offset used once, usually stays a plain number in the spec.
Name by role, not by appearance
A good token name says what the value is for. A name like blue-500 describes how it looks. If the brand moves to green, the name becomes wrong. A name like color.brand.primary stays correct.
Use a consistent pattern. A common one is category, then group, then variant:
| Pattern part | Example | Meaning |
|---|---|---|
| Category | `color` | The kind of value |
| Group | `brand` or `text` | Where it is used |
| Variant | `primary`, `hover`, `disabled` | Which version |
Pick one separator and one casing style, then keep them. Mixed styles such as brandPrimary and brand-primary force developers to guess.
A token file
Here is a small token file in JSON. Each token has a value.
{
"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" }
}
}The nesting becomes the name. color → brand → primary is read as color.brand.primary. The spacing steps follow a scale (8, 16, 24 pixels), so a designer picks a step instead of inventing a number.
From token to code
Tokens can be turned into CSS custom properties. A custom property is a named value in CSS, written with a leading -- and read with var(). The path of the token becomes the name, with dashes between the parts.
: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;
}Now a spec line such as "button padding: space-2 and space-3, radius: radius-md" maps directly to the code. Nobody has to measure pixels in the design file.
Common errors
- Names that describe looks.
light-graybreaks when the value turns darker. Name the role. - Too many tokens. A token for every pixel value hides the system. Keep the scale short.
- Mismatched names. If the design tool says
Primary/Blueand the code says--color-brand-primary, the handoff needs a translation. Use the same name in both places. - Hard-coded values left behind. The
#fffin the button above is a plain value. Add a token such ascolor.text.on-brandif it recurs.
Exercise
Your brand color changes from blue to green. You have a token named color-blue-500 used on every primary button. Why is this name a problem, and what would be a better name?
Show answer
The name describes the appearance, so after the change it would say "blue" while holding a green value, which misleads everyone. A role-based name such as color-brand-primary stays correct, and only its value changes.
Exercise
Convert this token path into a CSS custom property name: space → 3, with value 16px. Then write the declaration.
Show answer
The name is --space-3, and the declaration is --space-3: 16px; placed inside :root.