Sub topic 7
Set a type scale and heading rhythm
This chapter assumes you have a low-fidelity wireframe with ranked content, and that you know basic CSS terms such as font-size, rem, and custom properties. Typography is the first visual layer you add to the wireframe. It shows the information hierarchy without any color or imagery.
Why a scale beats ad hoc sizes
A type scale is a short, fixed list of font sizes that you reuse across the page. Picking sizes one at a time ("this heading feels a bit bigger") produces many near-identical values, and the hierarchy becomes hard to read. A scale gives each level of your ranking one size, so the reader can tell what matters by size alone.
Two common ways to build a scale:
- Ratio-based: start from a body size and multiply by a fixed ratio, such as 1.25 (major third). With a 1rem body, the steps are 1rem, 1.25rem, 1.5625rem, 1.953rem, and 2.441rem.
- Hand-picked: choose a few sizes that look right and round them, such as 1rem, 1.75rem, and 2.5rem.
The homepage in this tutorial uses the hand-picked approach because it needs only three levels: body, section heading (h2), and hero heading (h1).
| Level | Element | Size | Role |
|---|---|---|---|
| Body | `p` | 1rem | Running text and supporting lines |
| Section heading | `h2` | 1.75rem | Names each section |
| Hero heading | `h1` | 2.5rem | The single promise at the top |
Use rem units so sizes follow the reader's browser font setting. Pixel sizes ignore that setting.
Heading rhythm
Heading rhythm is the repeated pattern of space and size around headings. A reader scanning the page should see the same pattern in every section: a heading, a small gap, then content. Keep the space above a heading larger than the space below it. That way the heading visually belongs to the content under it, not the content above.
Apply the spacing scale from the previous chapter instead of new values. The CSS below stores the type scale as custom properties and sets the rhythm with spacing variables.
:root {
--space-1: 0.5rem;
--space-2: 1rem;
--space-3: 1.5rem;
--space-4: 2.5rem;
--font-size-body: 1rem;
--font-size-h2: 1.75rem;
--font-size-h1: 2.5rem;
}
body {
font-size: var(--font-size-body);
line-height: 1.5;
}
h1 {
font-size: var(--font-size-h1);
line-height: 1.2;
margin: 0 0 var(--space-2);
}
h2 {
font-size: var(--font-size-h2);
line-height: 1.25;
margin: var(--space-4) 0 var(--space-1);
}
p {
margin: 0 0 var(--space-2);
}Here each h2 has --space-4 (2.5rem) above and --space-1 (0.5rem) below. Large headings get tighter line height (1.2 to 1.25) because long line gaps look loose at big sizes. Body text keeps 1.5 for comfortable reading.
Common errors
- Too many sizes. More than four or five levels on a homepage blurs the hierarchy.
- Skipping levels for looks. Do not use an
h3because it is smaller. Choose the heading level for structure and set the size with CSS. - Equal space above and below headings. The heading then floats between two blocks and the grouping is unclear.
- Line length ignored. Keep body text to about 45 to 75 characters per line.
Exercise
A section heading has 1rem of space above it and 1.5rem below it, and it looks attached to the previous section. What is wrong, and how would you fix it using the spacing scale in this chapter?
Show answer
The space is reversed: the larger gap is below the heading, so it groups with the previous block. Put the larger gap above and the smaller gap below, for example margin: var(--space-4) 0 var(--space-1).