Sub topic 14
Adapting hierarchy across screen sizes
This chapter assumes you can write basic CSS and know custom properties (--name), rem units, and media queries. It also assumes you have read the earlier chapters on type scales, line height, line length, and spacing.
Why a hierarchy must adapt
A hierarchy that works on a 1440-pixel desktop display can fail on a 360-pixel phone. The causes are physical:
- A 44px headline at a 1:2.75 ratio to body text is dramatic on a wide screen. On a narrow screen it can wrap onto five lines and push the first paragraph below the fold.
- Body text at 16px is comfortable on both screens, but the reading distance and column width differ. The line length that was right at 65 characters on a desktop may become 35 characters on a phone.
- A 2em space above a subhead is generous on a tall desktop page. On a phone the same space can use up a fifth of the visible screen.
The goal is not identical sizes. The goal is that the relationships between levels survive: the headline still reads first, subheads still group the content, and body text stays the comfortable baseline. Adapting hierarchy means deciding which relationships to preserve and which to compress.
What to keep fixed and what to vary
Treat body text as the anchor. Its size should stay close to 1rem (usually 16px) across all screens, because the reader's comfort at that size does not shrink with the device. Most of the adaptation happens in the larger levels.
| Property | Typical adaptation | Reason |
|---|---|---|
| Body size | Stay at 1rem to 1.125rem | Readers hold phones close, so legibility does not require a larger size. |
| Headline size | Scale with the viewport, with a floor and a cap | The top level has the most room to shrink without losing rank. |
| Scale ratio | Smaller on phones (about 1.2), larger on desktops (about 1.25 or more) | A gentler ratio keeps big levels from overwhelming a narrow column. |
| Line height | Slightly tighter on large headings, steady on body text | Wrapping headlines look loose if leading stays at 1.5. |
| Measure | Set in `ch`, so it follows the text | On phones the screen width limits the line, not your rule. |
| Spacing | Reduce proportionally on small screens | Keeps headings close to their text without wasting screen height. |
Fluid type with clamp()
A fixed font-size combined with breakpoints produces jumps. Fluid type uses clamp(min, preferred, max) so size changes smoothly. The browser picks the preferred value but never goes below the minimum or above the maximum.
h1 {
font-size: clamp(1.75rem, 1.2rem + 2.5vw, 2.75rem);
}
body {
font-size: 1rem;
}Work out what this does. The preferred value is 1.2rem + 2.5vw. With a 16px root, 1.2rem is 19.2px, and 2.5vw is 2.5% of the viewport width.
- At 320px wide, the preferred value is 19.2 + 8 = 27.2px. That is below the 28px minimum, so the headline stays at 28px.
- At 640px wide, it is 19.2 + 16 = 35.2px.
- At 992px wide, it reaches 44px, which is the maximum. Wider screens stay at 44px.
So the headline grows only between about 352px and 992px. The headline-to-body ratio moves from 1.75 at the small end to 2.75 at the large end. That is the point of the technique: contrast increases as space becomes available.
The chart shows the headline size as the viewport widens.
Why the rem part matters
The preferred value mixes rem and vw on purpose. If you write font-size: 4vw alone, the text responds only to window width. When a reader zooms the page or raises their browser's default font size, the text does not grow, which breaks WCAG success criterion 1.4.4 (Resize Text). Adding a rem term keeps part of the size tied to the user's settings, and zooming still enlarges the text.
Scaling the whole scale
Fluid headings are one way to adapt. Another is to define the scale itself with two sets of values and switch between them. This keeps every level in step, so a subhead never ends up bigger than it should relative to the headline.
:root {
--step-0: 1rem;
--step-1: 1.2rem;
--step-2: 1.44rem;
--step-3: 1.728rem;
--step-4: 2.074rem;
}
@media (min-width: 48em) {
:root {
--step-1: 1.25rem;
--step-2: 1.563rem;
--step-3: 1.953rem;
--step-4: 2.441rem;
}
}
body { font-size: var(--step-0); }
h3 { font-size: var(--step-1); }
h2 { font-size: var(--step-2); }
h1 { font-size: var(--step-4); }Below 48em (768px at the default size) the scale uses a 1.2 ratio. From 48em up it uses 1.25. The element rules never change. Only the variables change, so the hierarchy stays consistent by construction.
Use em in the media query rather than px. Then the breakpoint also responds when users enlarge their default text size.
Choosing between the two approaches
| Approach | Strength | Weakness |
|---|---|---|
| `clamp()` on each level | Smooth, no jumps, little code | Each level needs its own tuned formula, so ratios can drift. |
| Variables switched at breakpoints | Ratios stay exact within each range | Visible jump at the breakpoint. |
| Both combined | Smooth size with controlled ratios | More setup and more to test. |
For most layouts, clamp the top two or three levels and leave body text fixed. That gets most of the benefit with the least risk.
Leading, measure, and spacing on small screens
Resizing the font is not enough. The surrounding properties need to follow.
Leading: a headline wrapping to three lines at line-height 1.5 looks like separate sentences. Keep large headings tight (about 1.1 to 1.2) at every size, and keep body text near 1.5.
Measure: a max-width: 65ch rule only caps the line. On a phone the viewport is narrower than 65ch, so the line fills the screen minus padding, giving perhaps 35 to 45 characters. That is acceptable. Below roughly 30 characters, words break unevenly and reading slows, so keep side padding modest.
Spacing: express margins in em so they scale with the text, and keep the rule that space above a subhead exceeds space below. You can reduce the multiplier on small screens.
h2 {
font-size: var(--step-2);
font-weight: 600;
line-height: 1.2;
margin-top: 1.5em;
margin-bottom: 0.5em;
}
@media (min-width: 48em) {
h2 { margin-top: 2em; }
}
p {
max-width: 65ch;
padding-inline: 1rem;
}Common failure modes
- Headline too large for the column. Long words such as "Responsibilities" can overflow a narrow screen at big sizes. Lower the minimum in
clamp()or addoverflow-wrap: break-wordas a safety net. - Collapsed hierarchy. If every level shrinks toward body size, subheads lose their rank. Check that adjacent levels still differ by at least a visible step, usually 15 to 25 percent.
- Inverted hierarchy. Unequal clamp formulas can let an h2 outgrow an h1 at some width. Check this at several widths, not just the extremes.
- Pixel-locked sizes. Sizes in
pxignore the user's default font size. Preferrem. - Testing only at breakpoints. Problems often show up at in-between widths, such as a tablet in portrait.
Testing the adapted hierarchy
Apply the same checks you use on desktop, once per size class.
- Squint test. Blur your eyes at 360px, 768px, and 1280px. The reading order should be the same each time: headline, subheads, body.
- Scan test. Scroll quickly and read only the headings. They should still summarize the page.
- Zoom test. Zoom to 200% and raise the browser's default font size. Nothing should overlap or be cut off, and the text should actually grow.
- Real device. Emulators match sizes but not reading distance or glare. Check at least one real phone.
Exercise
A page uses h1 { font-size: clamp(1.75rem, 1.2rem + 2.5vw, 2.75rem); } with a 16px root. At what viewport width does the headline reach its 44px maximum, and why is the rem term in the preferred value important?
Show answer
Set 19.2 + 0.025 × width = 44, which gives a width of 992px. Above that the headline stays at 44px. The rem term (1.2rem) ties part of the size to the user's browser font settings, so zooming or raising the default font size still enlarges the text. With vw alone, the text would ignore those settings and fail WCAG 1.4.4.
Exercise
You switch the type scale from a 1.2 ratio to a 1.25 ratio at a 48em breakpoint by redefining custom properties. Why is it better to change the variables than to rewrite the h1, h2, and h3 rules inside the media query?
Show answer
The element rules stay unchanged, so every level moves together and the ratios between levels stay consistent. Rewriting each rule invites mistakes, such as an h2 being updated while an h3 is not, which can collapse or invert the hierarchy.