Sub topic 3
Building a consistent type scale
A type scale is a fixed set of font sizes that you reuse across a page. This chapter shows how to build one from a ratio, how to express it in CSS, and where it fails. It assumes you know basic CSS (selectors, properties, custom properties, the box model) and the HTML heading elements. The previous chapter covered size as a cue: larger elements are seen first. Here you control that cue so the size differences are predictable.
Why a scale instead of picking sizes by eye
Without a scale, sizes tend to accumulate one at a time: 17px for a caption, 19px for a card title, 22px for a section heading. The differences between neighbors are small and inconsistent. Readers see "slightly different" text rather than a clear level, and the hierarchy blurs.
A scale fixes this in three ways:
- Distinct levels. Each step is far enough from its neighbors to read as a separate level.
- Consistency. The same role gets the same size on every page.
- Fewer decisions. You choose a base size and a ratio once, then pick a step by name.
The modular scale
A modular scale multiplies a base size by a constant ratio for each step. If the base is 1rem and the ratio is 1.25, then:
- step 0 = 1rem
- step 1 = 1rem × 1.25 = 1.25rem
- step 2 = 1rem × 1.25² ≈ 1.563rem
- step 3 = 1rem × 1.25³ ≈ 1.953rem
- step 4 = 1rem × 1.25⁴ ≈ 2.441rem
A ratio of 1.25 is called a major third in music-derived naming. Because every step is 25% larger than the one before, the visual jump between levels feels even.
Common ratios and what they suit:
| Ratio | Name | Typical use |
|---|---|---|
| 1.125 | Major second | Dense interfaces, dashboards, small screens |
| 1.200 | Minor third | Apps and documentation |
| 1.250 | Major third | General content sites and articles |
| 1.333 | Perfect fourth | Marketing pages with a strong headline |
| 1.500 | Perfect fifth | Editorial layouts with dramatic contrast |
| 1.618 | Golden ratio | Display-heavy pages; steps grow quickly |
A larger ratio gives stronger hierarchy but uses up space quickly. At 1.618, step 4 is about 6.9 times the base size, which is too large for most body-width columns.
Expressing the scale in CSS
Custom properties let you name each step once and reuse it. Using rem units ties every size to the user's root font size, so people who raise their browser's default text size get a proportionally larger page.
: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; }Notes on this example:
- The values are rounded to three decimals. Browsers handle fractional rem values, and the rounding error is far below one pixel.
--step-3is defined but unused. A scale is a menu of allowed sizes, and you do not have to use every step.- Headings skip from
h2(step 2) toh1(step 4). Skipping a step gives the page title extra weight. This is a design choice about size only. Heading levels in the HTML should still follow document structure. h1gets a tighterline-heightof 1.15. Large text needs less leading than body text, because the same line-height ratio produces a larger absolute gap as the font grows.
Computing the scale with calc()
You can generate steps from a single ratio so that changing the ratio updates everything. This is more compact, though the output is the same.
:root {
--ratio: 1.25;
--step-0: 1rem;
--step-1: calc(var(--step-0) * var(--ratio));
--step-2: calc(var(--step-1) * var(--ratio));
--step-3: calc(var(--step-2) * var(--ratio));
--step-4: calc(var(--step-3) * var(--ratio));
}Use this form while you are experimenting with ratios. Once you settle, hard-coded values are easier to read in browser developer tools, which show the computed result for either form anyway.
Choosing the base size and ratio
Start with the base, because body text is where readers spend most of their time.
- Base size. Leave body text at
1rem, which is 16px in most browsers. Smaller body text hurts readability. Do not set the rootfont-sizein pixels, because that overrides the user's preference. - Ratio. Pick the smallest ratio that still makes headings clearly different from body text. If you can't tell
h2fromh3at a glance, the ratio is too small. - Number of steps. Most pages need four to six sizes. If you need more, you probably have too many levels of emphasis.
- Steps below the base. Add a step under 1 (for example
0.8rem) for captions and legal text. Keep it at or above about 0.75rem so it stays legible.
Size is not the only type cue
A scale gives you sizes. Weight and color also separate levels, and they let you keep the scale tight. A page with a 1.2 ratio can still have a clear hierarchy if headings are bold and body text is regular. The reverse is also true: a bold, same-size label next to body text produces a mild distinction without needing a new step.
Use the scale for the major levels (title, section heading, body) and use weight for finer distinctions inside a level, such as a bold lead-in phrase in a paragraph.
Line height and measure go with the scale
Changing size without adjusting spacing makes text look off. Two settings matter most:
- Line height. Body text reads well at about 1.4 to 1.6 times its size. Headings, being larger and shorter, usually need 1.1 to 1.3. Unitless values (like
1.5) scale with the element's font size, so they are safer than fixed lengths. - Measure. This is the line length. About 45 to 75 characters per line is comfortable. Large headings wrap sooner, which is fine, but avoid a heading that leaves one word alone on the last line.
You can express a comfortable measure with the ch unit:
.article {
max-width: 65ch;
}Edge cases and common errors
Too many sizes
If the stylesheet contains a dozen unrelated font-size values, the scale has been bypassed. Search for font-size: and replace hard-coded values with var(--step-n). Any size not on the scale needs a reason.
Mixing px and rem
If some elements use pixel sizes and others use rem, users who change their default text size will see only part of the page change, and the proportions between levels break. Use rem for the scale. Use em only when you want a size relative to the parent, such as an icon next to text.
Nested em compounding
em is relative to the parent element's font size. A list inside a list with font-size: 1.25em on each level compounds: 1.25 × 1.25 = 1.5625 times the original. This is a common cause of "why is this text so big?". Setting scale sizes in rem avoids it, since rem always refers to the root.
A ratio that is too aggressive for small screens
A 1.5 ratio gives step 4 a size of about 5.06rem, which is roughly 81px. On a 320px-wide phone, a long heading at that size wraps into many short lines or overflows. The next section shows a partial fix, and a later chapter covers responsive hierarchy in full.
Hierarchy that depends on size alone
If two elements differ only by size and the difference is small, the cue is weak. Check that adjacent steps are visibly different, and add weight or color when they are not.
Scaling the scale on small screens
One way to keep large steps from overwhelming a narrow screen is to use a different ratio per breakpoint. Another is to use clamp() to make the largest steps fluid.
:root {
--step-0: 1rem;
--step-1: 1.125rem;
--step-2: 1.266rem;
--step-3: 1.424rem;
--step-4: 1.602rem;
}
@media (min-width: 48rem) {
:root {
--step-1: 1.25rem;
--step-2: 1.563rem;
--step-3: 1.953rem;
--step-4: 2.441rem;
}
}Here the small-screen scale uses a 1.125 ratio and the larger one uses 1.25. Because the headings reference var(--step-n), no other rule has to change. The trade-off is that sizes jump when the viewport crosses 48rem. A fluid approach avoids the jump, and the later chapter on responsive hierarchy covers it.
Putting it together: a quick audit
Use this procedure on an existing page:
- List every distinct
font-sizevalue. A browser's developer tools or a search of the stylesheet will give you the list. - Check whether those values fall on one ratio. If neighbors differ by less than about 10%, merge them.
- Assign roles: page title, section heading, subheading, body, small text.
- Replace the raw values with the named custom properties.
- Reload and view the page at 200% browser zoom. Everything should scale together.
Summary
A modular type scale multiplies a base size by one ratio to produce a short list of distinct sizes. Define the steps as custom properties in rem, assign them to roles, and pair them with sensible line height. Pick a ratio that suits the content and screen size, and use weight and color for distinctions smaller than a step. The scale sets how much larger one level is than another, which makes size a dependable cue for the rest of the hierarchy.
Exercise
A stylesheet uses a base of 1rem and a ratio of 1.2. Calculate the sizes for steps 1, 2, and 3, rounded to three decimals. Then say whether a heading at step 3 would be clearly distinct from body text.
Show answer
Step 1 = 1 × 1.2 = 1.2rem. Step 2 = 1.2 × 1.2 = 1.44rem. Step 3 = 1.44 × 1.2 = 1.728rem. A step 3 heading is about 73% larger than body text, which is clearly distinct. Adjacent steps differ by only 20%, so step 1 against body text is a weaker difference, and it should be supported by bold weight or color.
Exercise
A nested list sets font-size: 1.25em on every li. The outer item renders at 20px, and the item three levels deep looks far larger. Why, and how do you fix it?
Show answer
em is relative to the parent's computed font size, so each level multiplies the previous one: 20px, 25px, 31.25px, and so on. Fix it by using a rem-based size from the scale, such as font-size: var(--step-1), applied once, or by setting nested li elements to font-size: inherit. This way the size does not compound.
Exercise
Your design uses a 1.5 ratio and the h1 is too big on phones. Name two ways to address this without changing the body text size.
Show answer
Use a smaller ratio (for example 1.125 or 1.2) for narrow viewports by redefining the step custom properties inside a media query, or make the largest steps fluid with clamp(). Either way the headings keep referencing var(--step-n), so no other rules change.