Sub topic 5
Specifying typography and color
This chapter assumes you know how to use text styles and color styles in your design tool. It also assumes you have read the chapter on design tokens. Here you will turn the type and color choices in your design into specs a developer can implement without measuring pixels or sampling colors.
What a type spec must say
A developer cannot read a font setting off a screenshot. Give each text style a name and a full set of properties:
- Font family, with a fallback stack (for example, a system sans-serif).
- Font size, in px in the design file. Say whether the developer should use
rem. - Font weight, as a number such as 400 or 600.
- Line height, as a unitless ratio such as 1.5. Pixel values in design tools are easy to misread.
- Letter spacing, only where it differs from the default.
- Where the style is used, such as "page title" or "form label".
Name styles by role, not by appearance. heading-lg survives a redesign. blue-bold-32 does not.
| Style name | Size | Weight | Line height | Use |
|---|---|---|---|---|
| `body-md` | 16px | 400 | 1.5 | Paragraphs |
| `label-sm` | 14px | 600 | 1.4 | Form labels |
| `heading-lg` | 32px | 700 | 1.2 | Page titles |
If sizes change at a breakpoint, list each size in the table. The responsive chapter covers how to describe that change.
Type styles as CSS
Typography tokens map to custom properties and a class per role. A developer can compare this code to your table line by line.
:root {
--font-family-base: "Inter", system-ui, sans-serif;
--font-size-body-md: 1rem;
--font-weight-regular: 400;
--line-height-body: 1.5;
}
.text-body-md {
font-family: var(--font-family-base);
font-size: var(--font-size-body-md);
font-weight: var(--font-weight-regular);
line-height: var(--line-height-body);
}Name the font files too. If the design uses a web font, state the source (a hosted service or files you supply), the weights needed, and the format. Each extra weight adds download size, so list only the weights the design uses.
What a color spec must say
Every color in the design should come from a named token, never a loose hex value. Use two layers of names:
- Palette tokens describe the raw value, such as
blue-600. - Semantic tokens describe the job, such as
color-text-defaultorcolor-brand-primary.
Components should reference the semantic layer. When the brand color changes, you update one token and every component follows.
{
"color": {
"text": {
"default": { "value": "#1a1a1a" },
"disabled": { "value": "#8a8a8a" }
},
"brand": {
"primary": { "value": "#1f5fd1" }
}
}
}State the format for any value with transparency. Write rgba(26, 26, 26, 0.6) or an eight-digit hex value, and say which one you mean. Opacity set on a layer in the design tool is not the same as opacity in a color, because layer opacity also fades the children.
Check contrast before handoff
Contrast is part of the spec, not a later review step. WCAG 2.2 asks for a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text and interface component borders. White text on #1f5fd1 gives about 5.8:1, which passes. Gray #8a8a8a on white is about 3.5:1, which fails for normal text. Disabled controls are exempt from the requirement, but do not use that gray for text people must read.
Write the pairing next to the color: "text-default on surface-page, 16.9:1". Developers can then see that the pair was checked and which pairs are approved.
Common errors
- Handing over a font name without weights, so the developer picks the wrong one.
- Using pixel line heights that break when the font size changes.
- Pasting hex values into the spec instead of token names.
- Using color as the only signal, such as red text for an error with no icon or message.
- Leaving out link colors for visited and focus states. The next chapters on component states cover those.
Exercise
A button label uses white text on a background of #1f5fd1. The spec says "blue, bold, 14px". Rewrite it as a spec a developer can implement, and name two properties that are missing.
Show answer
Use roles and tokens: "label-sm (14px, weight 600, line height 1.4) in color-text-on-brand on color-brand-primary (#1f5fd1)". Missing properties are line height and the exact weight (the word "bold" is ambiguous), and the family and fallback stack. A good answer also lists the contrast ratio, about 5.8:1, as passing.