Sub topic 5
Specifying Typography and Color
This chapter assumes you know how to build text styles and color styles in a design tool, and that you have read the chapter on design tokens. You should also know basic CSS: font-size, line-height, and how a color value is written in hex. By the end, you will be able to write type and color specs that a developer can implement without measuring or guessing.
Why type and color specs fail
Most typography and color problems in a handoff have the same cause. The designer gives values as they appear on the canvas, such as "Inter, 16, Regular, #1A1A1A". The developer then has to decide what is a one-off and what is a rule. They also have to convert units, and they have to guess what happens when the text wraps or the background changes.
A good spec answers four questions for every style:
- What is the style called, and where is it used?
- What are its exact values, in units the browser understands?
- What does it do when the content is longer, shorter, or on a different background?
- Which contrast and accessibility checks does it pass?
Typography specs
What a text style must contain
A text style is a bundle of properties. Leave one out and the developer fills the gap with a default that may not match your design.
| Property | CSS property | What to write in the spec |
|---|---|---|
| Font family | `font-family` | The primary family, plus a fallback stack |
| Size | `font-size` | A value in `px` or `rem`, and which one you mean |
| Weight | `font-weight` | A number such as 400 or 600, not "Semibold" |
| Line height | `line-height` | A unitless ratio or a pixel value |
| Letter spacing | `letter-spacing` | A value in `em`, converted from the tool's percent |
| Case | `text-transform` | None, uppercase, or capitalize |
| Alignment | `text-align` | Left, center, or right, and whether it changes on small screens |
Weight names differ between font files. "Semibold" in one family is 600, and in another it may be 500. Always give the number.
Units: pixels, rem, and unitless line height
Design tools measure in pixels. Developers often write type in rem, which is relative to the root font size. In most browsers the root size is 16px by default, so 1rem equals 16px. Using rem lets text scale when a user raises their browser's default font size, which matters for accessibility.
State your convention once in the file and apply it everywhere. For example: "All font sizes are given in px at the 16px root. Implement as rem (size ÷ 16)."
Line height needs the same care. A tool may show "line height 24" on a 16px font. In CSS, the better form is the unitless ratio 1.5, because it scales with the font size and avoids surprises when a child element has a different size. Give both: "24px (1.5)".
Letter spacing is another conversion trap. Figma shows it as a percentage of the font size. CSS wants em, where 1% equals 0.01em. A tracking of 2% becomes letter-spacing: 0.02em.
Naming type styles by role
Name styles for what they do, not for how they look. heading-lg survives a redesign. blue-bold-32 does not.
A type scale is a fixed set of sizes that styles are drawn from. A small one might look like this:
| Style name | Size | Line height | Weight | Typical use |
|---|---|---|---|---|
| `heading-xl` | 40px | 48px (1.2) | 700 | Page title |
| `heading-lg` | 28px | 36px (1.29) | 700 | Section title |
| `body-md` | 16px | 24px (1.5) | 400 | Paragraph text |
| `body-sm` | 14px | 20px (1.43) | 400 | Captions, helper text |
| `label` | 14px | 20px (1.43) | 600 | Form labels, buttons |
Each row can be stored as a token group, so one name carries all its properties. Here is a JSON sketch of a text style, in the same shape as the token file from the previous chapter:
{
"font": {
"family": {
"sans": { "value": "Inter, system-ui, sans-serif" }
},
"size": {
"body-md": { "value": "1rem" },
"heading-lg": { "value": "1.75rem" }
},
"weight": {
"regular": { "value": "400" },
"bold": { "value": "700" }
},
"line-height": {
"body-md": { "value": "1.5" },
"heading-lg": { "value": "1.29" }
}
}
}And a possible CSS result:
:root {
--font-family-sans: Inter, system-ui, sans-serif;
--font-size-body-md: 1rem;
--font-size-heading-lg: 1.75rem;
--font-weight-regular: 400;
--font-weight-bold: 700;
--line-height-body-md: 1.5;
--line-height-heading-lg: 1.29;
}
body {
font-family: var(--font-family-sans);
font-size: var(--font-size-body-md);
font-weight: var(--font-weight-regular);
line-height: var(--line-height-body-md);
}
h2 {
font-size: var(--font-size-heading-lg);
font-weight: var(--font-weight-bold);
line-height: var(--line-height-heading-lg);
}Fonts the developer has to load
A text style is only as good as the font file behind it. List these items in the handoff:
- The exact family name and where the files come from, such as a licensed foundry or a hosted service.
- Each weight and style in use. Loading 400 and 700 costs less than loading six weights, so remove any that the design does not use.
- The fallback stack. If the web font fails or loads late, the browser shows a fallback. Choose one with similar proportions so the layout does not jump.
- The loading behavior you expect.
font-display: swapshows fallback text at once and swaps when the font arrives. Say so if you prefer it. - Licensing for web use. A desktop license does not always cover websites.
Edge cases in text
Static mockups show perfect text. Real content does not behave that way. Document these cases for any style used in a flexible container:
- Long words and names. Say whether text wraps, breaks, or truncates with an ellipsis.
- Line count limits. A card title might clamp to two lines. Write "max 2 lines, then ellipsis".
- Line length. Body text reads best at roughly 45 to 75 characters per line. Give a maximum width for paragraphs, for example
max-width: 65ch. - Missing glyphs. If the product shows names in several languages, check that the font covers those scripts.
- Text that grows. Languages such as German often run 30 percent longer than English. Buttons and labels need room.
Color specs
Name colors by purpose
Raw hex codes in a spec invite mistakes. If a developer sees #1F5FD1 in twelve places, they cannot tell which uses are the same decision. Use two layers of naming:
- Base (or palette) tokens name the raw colors, such as
blue-600. They describe what the color is. - Semantic tokens name the job, such as
color-action-primary. They point to a base token and describe what the color is for.
Components should use only semantic tokens. When the brand blue changes, you edit one reference instead of hunting through every component. Semantic tokens also make themes possible, because color-text-default can point to a dark gray in the light theme and a near-white in the dark theme.
| Semantic token | Light theme value | Dark theme value | Use |
|---|---|---|---|
| `color-text-default` | `#1A1A1A` | `#F2F2F2` | Body text |
| `color-text-disabled` | `#8A8A8A` | `#6B6B6B` | Disabled controls |
| `color-action-primary` | `#1F5FD1` | `#6B9BF0` | Buttons, links |
| `color-feedback-error` | `#B3261E` | `#F2B8B5` | Error text and borders |
Color formats and transparency
Specify colors in a format that survives the trip to code. Hex is the usual choice for opaque colors. If a color is partly transparent, do not give an opacity on the layer and a hex on the fill separately, because the developer may apply only one. Write the final form, for example rgb(26 26 26 / 60%), and name the color that sits behind it.
Be careful with gradients and shadows. List each stop with its position and color. For a shadow, give x offset, y offset, blur, spread, and color. Without these five values, the developer eyeballs it.
Contrast checks
Contrast ratio compares the brightness of text and its background. The Web Content Accessibility Guidelines (WCAG) set the minimum ratios for level AA:
| Content | Minimum ratio |
|---|---|
| Normal body text | 4.5 : 1 |
| Large text (about 24px, or 19px bold) | 3 : 1 |
| UI component borders and icons needed to understand a control | 3 : 1 |
Check every text and background pair that the design uses, including the ones that appear only in a state, such as white text on a hover background. Record the ratio in the spec. A line such as "color-text-disabled on white: 3.4 : 1, exempt as disabled" tells the developer the low value is deliberate and not a mistake.
Do not use color alone to carry meaning. An error field that turns red but has no icon or message fails for users who cannot tell the colors apart. Pair color with text, an icon, or a pattern.
From spec to code
The most useful test of a spec is whether it maps cleanly to a selector. This button uses the tokens above, and every value traces back to a name in the handoff:
.button {
font-family: var(--font-family-sans);
font-size: var(--font-size-body-md);
font-weight: 600;
line-height: var(--line-height-body-md);
color: #fff;
background: var(--color-action-primary);
}If the developer must write a value that has no token, either the spec is missing a style or the design has a one-off. Both are worth a conversation, and the next diagram shows where each value should come from.
Common errors
- Weight given as a name. "Semibold" is ambiguous. Write 600.
- Line height in percent only. Tools show 150%, which can be copied into CSS as a non-unitless value in some workflows. Write the unitless ratio.
- Letter spacing copied as percent. CSS does not accept a bare percent here. Convert to
em. - Colors that exist only on the canvas. A color with no token name will be hard-coded. Give it a name or remove it.
- Contrast checked only in the default state. Hover, focus, disabled, and dark-theme pairs need checks too.
- Text styles with no content rules. If you do not say how long text behaves, the developer chooses.
Checklist before you hand off
- Every text style has a role-based name and all seven properties from the table.
- Units are stated once and used consistently.
- Fonts, weights, fallbacks, and license are listed.
- Every color is a semantic token that points to a base token.
- Each text and background pair has a recorded contrast ratio.
- Long, short, and wrapped text cases are documented for flexible containers.
Exercise
A designer's spec says: "Body text: Inter Semibold, 16, line height 150%, tracking 2%, color #1A1A1A." Rewrite it so a developer can implement it directly. Name the style, give CSS-ready values, and say which token layer the color belongs to.
Show answer
Name the style by role, for example label or body-strong. Then write: font-family Inter with a fallback stack (Inter, system-ui, sans-serif); font-size 1rem (16px at a 16px root); font-weight 600, since "Semibold" is a name and not a value; line-height 1.5 (24px); letter-spacing 0.02em, converting 2% to em; color color-text-default, a semantic token that points to a base gray token with the value #1A1A1A. Add the contrast ratio of the text on its background and a rule for wrapping, such as the maximum line length.
Exercise
Your design has a primary button with white text on a #1F5FD1 background. The hover state uses #174AA6, and the disabled state uses #8A8A8A text on a transparent background over white. Which contrast checks should you record, and why does the disabled pair need a note?
Show answer
Record three pairs: white on #1F5FD1 (default), white on #174AA6 (hover), and #8A8A8A on white (disabled). The first two need at least 4.5 : 1 for normal-size text, or 3 : 1 if the text is large. The disabled pair has a low ratio, roughly 3.4 : 1, which is below 4.5 : 1. WCAG exempts disabled controls from the contrast requirement, but the spec should say that the low value is intentional, so the developer does not "fix" it and the reviewer does not flag it as an error.