Sub topic 3
Building a consistent type scale
This chapter assumes you know basic HTML (headings, paragraphs) and basic CSS (selectors, custom properties, rem units). Earlier in this tutorial you saw that larger elements are noticed first. A type scale turns that idea into a repeatable system. You pick a base size and a ratio, then derive every other size from them.
Why use a scale
Without a scale, font sizes tend to drift. A heading is 22px here, 26px there, and 28px on another page. The differences are too small to read as intentional, so they blur the hierarchy instead of building it.
A modular scale fixes this. You choose:
- A base size, usually the body text size (
1rem, typically 16px). - A ratio, the number each step is multiplied by to get the next step.
Each step is the previous step times the ratio. Common ratios are 1.2 (minor third), 1.25 (major third), and 1.333 (perfect fourth). Small ratios give subtle differences. Large ratios give dramatic ones.
Computing the steps
With a base of 1rem and a ratio of 1.25, the steps are:
| Step | Calculation | Size (rem) |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 1 × 1.25 | 1.25 |
| 2 | 1.25 × 1.25 | 1.563 |
| 3 | 1.563 × 1.25 | 1.953 |
| 4 | 1.953 × 1.25 | 2.441 |
Steps are rounded to three decimals, which is precise enough for the browser. Step n equals the base times the ratio raised to the power n.
Putting the scale in CSS
Custom properties store the steps in one place. Elements then refer to the steps by name instead of repeating raw numbers.
:root {
--step-0: 1rem;
--step-1: 1.25rem;
--step-2: 1.563rem;
--step-3: 1.953rem;
--step-4: 2.441rem;
}
body { font-size: var(--step-0); line-height: 1.5; }
h3 { font-size: var(--step-1); }
h2 { font-size: var(--step-2); }
h1 { font-size: var(--step-4); line-height: 1.15; }Notice three choices in this code:
- Sizes use
rem, so they scale when users change their browser's default font size. h1uses--step-4and skips--step-3. You do not have to use every step. Skipping one widens the gap between the page title and the section headings, which makes the title more dominant.- Body text has
line-height: 1.5for comfortable reading, while the largeh1has a tighter1.15. Large text looks loose with the same ratio of spacing, so tighten it as size grows.
Choosing a ratio
The ratio sets how strong the hierarchy feels. Pick it based on the page's job.
- Dense interfaces such as dashboards need many sizes in a small range. Use 1.125 to 1.2.
- Articles and general sites work well at 1.25.
- Marketing pages and landing pages can use 1.333 or more for a bold title.
A ratio that is too small is a common error. If h2 and h3 differ by only 1.05 times, readers cannot tell them apart and rely on weight or color to do the work. A ratio that is too large produces a title that overwhelms everything else and may not fit on narrow screens.
Common errors
- Mixing scale and arbitrary sizes. Adding a one-off
1.4remfor a single card breaks the pattern. If you need a new size, add a step, not a number. - Using size alone for every level. Six heading levels rarely need six distinct sizes. Two or three clear sizes, plus weight differences, often read better.
- Using
pxfor font sizes. Pixel values ignore the user's font size preference. Userem. - Making body text too small. The base step anchors the whole scale. A base below 1rem makes every step smaller too.
Next step
A scale gives you consistent sizes. Size is only one cue, though. The next chapters add contrast and position, and later chapters show how to make the scale fluid across screen sizes.
Exercise
Your base size is 1rem and your ratio is 1.2. Compute step 3 to three decimal places. Then explain why a page title using step 3 may not stand out enough against step 2 headings.
Show answer
Step 3 is 1 × 1.2³ = 1.728rem. Step 2 is 1.2² = 1.44rem. The title is only 1.2 times larger than the step 2 headings, a difference of 0.288rem, which is small. To make the title dominant, skip a step (use step 4, 2.074rem) or choose a larger ratio such as 1.25 or 1.333.
Exercise
A stylesheet sets h1 to 2.2rem, h2 to 1.7rem, h3 to 1.45rem, and a card title to 1.6rem. List two problems with this approach and say how a type scale fixes them.
Show answer
First, the sizes follow no pattern, so the differences (0.5, 0.25, 0.15rem) are uneven and some levels look nearly identical. Second, the card title at 1.6rem sits between h2 and h3 without a clear reason, which creates competing emphasis. A scale gives each size a fixed relationship to the others, and any new element must pick an existing step instead of inventing a size.