Notes from building a small design system
This is placeholder content. It exists so the type and layout can be judged on a page that looks like real writing, and it will be replaced before launch.
For most of a year this site was a single page with a name on it. Every time I sat down to add something, I spent the evening choosing a shade of off-white instead. At some point it became clear that the problem wasn’t the colour. It was that every decision was being made from scratch, so none of them felt settled.
A design system sounds like something for a team of forty, but the useful part of the idea is small: write down the decisions once, give them names, and build everything else out of the names. This post is a record of what that looked like at the scale of one person and one website.
Start with what you already have
The first pass wasn’t design at all. It was an inventory. I went through the stylesheet and listed every size, colour and gap that appeared in it, and how often. A few things stood out straight away:
- There were eleven different font sizes, several of them within a pixel of each other.
- Spacing was a mix of
rem,emandpx, often in the same rule. - Colours were mostly consistent, because they had been named early on, which turned out to be the best argument for naming everything else.
None of this was wrong, exactly. It just meant that two components built a month apart would never quite line up, and I’d notice it every time.
Pick a scale, then round to it
Rather than invent new numbers, I took the values the site already used and moved each one to the nearest step of a short, regular scale. Body text stayed where it was. Headings moved by a pixel or two. The gaps between sections snapped to a four-pixel grid.
The result looked almost identical, which was the point. A scale is not meant to change how a page looks on the day you introduce it. It’s meant to make the next hundred decisions faster and more consistent than the last hundred.
Naming things
Names matter more than values. A value can change in one place; a name gets typed into every component. I ended up with three layers:
- Raw values, like the paper and ink colours or the space steps, which describe what something is.
- Roles, like the ground, the figure or the colour of a link, which describe what something is for and can swap between light and dark mode.
- Components, which only ever refer to roles and steps, never to raw values or one-off numbers.
The middle layer does most of the work. When dark mode arrived, almost nothing in the components had to change, because they had never known what colour the background actually was.
The most useful rule turned out to be the most boring one: if a number appears in a component, it should have a name somewhere else.
What the tokens look like
In practice the tokens are plain CSS custom properties, generated from a single source file so the design-system pages and the site can’t drift apart:
:root {
--lex-text-md: 1.125rem;
--lex-leading-body: 1.6;
--lex-space-4: 1rem;
--lex-space-12: 3rem;
}
body {
font-size: var(--lex-text-md);
line-height: var(--lex-leading-body);
}
Nothing clever is happening here, and that’s deliberate. Anyone reading the stylesheet later, including me, should be able to see where a value comes from in one jump.
Line length
The decision I underestimated most was how wide a block of text should be. It is easy to set the width of the whole page and let the text fill it, but the page and the paragraph are answering different questions. The page needs room for navigation, images and tables. The paragraph needs to be comfortable to read.
Most guidance on reading puts a comfortable line somewhere between forty-five and seventy-five characters, and the Web Content Accessibility Guidelines suggest no more than eighty. Measured in the site’s typeface, the old column ran about eighty-five on an average line, and up to ninety. Separating the two widths fixed it without narrowing the header.
Here is how the options compared, measured on ordinary prose at 18px:
| Text width | Average characters per line | Longest line |
|---|---|---|
| 38em | 85 | 90 |
| 33em | 74 | 81 |
| 32em | 73 | 75 |
A unit that looks made for this, ch, turned out to be a trap. It measures the
width of the digit zero, which is unusually wide in this typeface, so a width of
80ch fits well over a hundred characters of actual text.
What I’d do differently
Looking back, a few things would have saved time:
- Write the inventory down before changing anything, so every later change can be compared with where it started.
- Agree the scales before building components, not after. Retrofitting names onto finished components is slower than starting with them.
- Keep a long, realistic sample page around, like this one, so layout decisions
are made against real text rather than a single sentence of placeholder copy.
- It should include the awkward parts: tables, code, quotations and long words.
- It should be long enough to scroll, because vertical rhythm only shows up over a whole page.
None of this is finished. The next step is a small set of components built only from these names: links, buttons, tags and the styles that make a post like this one readable. If they come together without any new numbers, the system is doing its job.