Sub topic 15
Testing and Refining a Hierarchy
This chapter assumes you know the basics of type (typeface, size, weight, italic) and can read simple HTML and CSS. It also assumes you have met the other chapters in this tutorial: type scales, leading, measure, spacing, contrast, and responsive type. Here you will use those ideas to check a finished layout and fix what is wrong with it.
Why test a hierarchy
A hierarchy that looks right to its designer can still fail readers. You have read the text many times, so you already know what matters. A new reader does not. Testing replaces your own familiarity with evidence about what a fresh reader sees first, second, and third.
A hierarchy is working when three things hold:
- The reader can tell which element is the headline, which are subheads, and which is body text without reading any of it.
- The reader can find a section by scanning subheads alone.
- Every level stays distinct and readable on every screen size you support.
Testing is cheap. Most of the checks below take a minute each. Run them in order, and fix problems at the earliest step where they appear, because later checks depend on earlier ones.
The squint test
The squint test checks whether the visual ranking survives when detail is removed. Step back from the screen or squint until the text blurs. You can also apply a blur filter in your design tool, or blur the page in the browser.
Letters become gray shapes. What remains is the pattern of size, weight, and spacing. Ask these questions:
- What do I notice first? It should be the headline.
- What do I notice second? It should be the subheads, or a lead paragraph if you have one.
- Can I see where body text starts and ends, and how it breaks into groups?
- Does anything compete with the headline, such as a large pull quote, a bright button, or a heavy image caption?
If two elements seem equally loud, the hierarchy has a tie. Ties are the most common failure. Break one by changing a single variable on one of them.
You can run a blur in the browser with a few lines of CSS pasted into the developer tools.
body {
filter: blur(4px);
}Remove the rule when you are done. The value of 4px suits normal body sizes. Raise it if you can still read the body text.
The outline test
The outline test checks that the markup states the same hierarchy the design shows. Assistive technology, search engines, and reader modes use the heading elements, not your CSS. If the visual levels and the markup disagree, some readers get a different document than the one you designed.
Write the structure as plain markup first.
<article>
<h1>Headline states the main idea</h1>
<p class="lead">A short intro sentence in slightly larger text.</p>
<h2>Subhead introduces a section</h2>
<p>Body text carries the detail.</p>
<h2>Another section</h2>
<p>More body text.</p>
</article>Then check the following:
- There is one
h1per page or article. - Levels do not skip, for example from
h2straight toh4. - Heading elements are chosen by structure, not by how big they look. If you want a smaller
h2, change the CSS, not the element. - Text that looks like a heading but is a bold paragraph has been converted to a real heading element.
Read only the headings, in order. If that list makes sense as a table of contents, the outline passes.
Checking the numbers
Visual tests catch what looks wrong. Numeric checks catch what looks acceptable but is not. Build a short list of values and compare them to your intended scale.
The type scale used in this tutorial starts from a 1rem body size and a ratio of 1.25.
: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); }
h3 { font-size: var(--step-1); }
h2 { font-size: var(--step-2); }
h1 { font-size: var(--step-4); }Look for these problems in the computed styles:
| Symptom | Likely cause | Fix |
|---|---|---|
| Subhead barely differs from body | Step is too small, or weight is the same | Move up one step or raise the weight |
| Headline and subhead look alike | Adjacent steps used for adjacent levels | Skip a step, as the scale above skips `--step-3` |
| Many near-identical sizes | Values typed by hand, not taken from the scale | Replace them with the variables |
| Body text under 16px | Base size set too small | Return the base to 1rem |
| Subhead sits closer to the previous paragraph | More space below than above | Put the larger margin above |
To find stray sizes, list every font-size in your stylesheet. Anything that is not a scale variable should have a reason.
grep -n "font-size" styles.cssTesting spacing and proximity
A heading must look attached to the text it introduces. Squint at the gaps. If the space above a subhead equals the space below it, the subhead floats between two paragraphs and the reader must guess which one it belongs to.
The fix is asymmetric spacing: more above, less below.
h2 {
font-size: 1.563rem;
font-weight: 600;
margin-top: 2em;
margin-bottom: 0.5em;
}
h2 + p {
margin-top: 0;
}The h2 + p rule removes any top margin on the paragraph that follows a subhead. Without it, the paragraph's own margin can add to the heading's bottom margin, and the gap grows past what you intended. Check this in the browser's box inspector. Margins between a heading and a paragraph can collapse, which means the larger of the two applies instead of their sum. That is a useful behavior, but it means you should measure the real gap rather than trust the numbers in the stylesheet.
Testing readability of the body text
Body text is where readers spend most of their time, so test it as its own unit. Check leading and measure together.
body {
font-family: Georgia, serif;
font-size: 1rem;
line-height: 1.5;
}
p {
max-width: 65ch;
}
h1 {
font-size: 2.441rem;
line-height: 1.15;
font-weight: 700;
}Count characters in a typical line. Roughly 45 to 75 characters is comfortable, and 65ch sits in that range. Lines much longer than that make the eye lose its place on the return sweep. Lines much shorter produce choppy reading and awkward gaps in justified text.
Then check leading. Tight leading makes lines look like a solid block, and loose leading makes paragraphs fall apart into separate lines. A unitless line-height of 1.5 scales with the font size of each element. The headline uses 1.15 because it is large and runs to only a few lines. Applying the body's 1.5 to a large headline leaves it looking gappy.
Contrast checks
Contrast is a numeric test with a published threshold. The Web Content Accessibility Guidelines (WCAG) define a contrast ratio between text color and background color. For level AA, normal text needs at least 4.5:1. Large text, which is about 24px regular or 18.66px bold and above, needs at least 3:1.
Use a contrast checker, or the color picker in browser developer tools, which reports the ratio. Test every pair, not just the body text:
- Body text on its background.
- Subheads, especially if you made them a lighter color to push them back.
- Captions and metadata, which are often set in light gray.
- Text over images or gradients, tested at the lightest and darkest points behind the text.
- Link colors against the body text and the background.
A common error is to lower the contrast of secondary text until it fails. If gray text is the way you rank captions below body text, check that the gray still reaches 4.5:1. If it does not, rank them by size or weight instead.
The resize test
A hierarchy that works at 1440px wide may collapse on a phone. Test at several widths, at least a small phone (about 360px), a tablet, and a wide desktop. Also test with the browser's text size raised to 200%, since many readers change it.
Fluid sizing with clamp() lets the headline grow with the viewport between a minimum and a maximum, so the gap between headline and body holds at every width.
h1 {
font-size: clamp(1.75rem, 1.2rem + 2.5vw, 2.75rem);
}
body {
font-size: 1rem;
}At each width, repeat the squint test. Watch for these failures:
- The headline wraps to five or six lines on a narrow screen. Lower the maximum or shorten the text.
- The headline and the first subhead end up within a step of each other at the small end.
- The measure grows past 75 characters on a wide screen because
max-widthwas not set. - Long words overflow the container at large text sizes.
Do not size the body text in vw units alone. Viewport units ignore the reader's own text size setting, and they can make text too small to read.
Refining: change one variable at a time
When a test fails, it is tempting to adjust size, weight, color, and spacing together. Then you cannot tell which change helped. Change one variable, rerun the test that failed, and keep the change only if it helps.
A useful order, from least to most disruptive:
- Spacing. It costs nothing in visual weight.
- Weight. A step from 400 to 600 often separates a subhead from body text.
- Size. Move one step on the scale, not an arbitrary amount.
- Color. Use it last, and recheck contrast after every change.
- Typeface. Change it only if the others have not worked.
Keep a short log of what you changed and why. When someone later asks why subheads use 600 and not 700, the log has the answer.
A review checklist
Use this list for a final pass.
- The squint test shows the headline first, subheads second, and body text as the quiet baseline.
- The headings alone read as a sensible outline, with no skipped levels.
- Every font size comes from the scale.
- Subheads have more space above than below.
- Body text has leading near 1.5 and a measure near 65 characters.
- Every text and background pair meets WCAG AA.
- The layout holds at phone, tablet, and desktop widths, and at 200% text size.
Exercise
A subhead looks like it belongs to the paragraph above it, not the one below. The stylesheet gives it margin-top: 0.5em and margin-bottom: 2em. Which test would reveal the problem, what is the fix, and what should you check afterward?
Show answer
The squint test, applied to the gaps, shows the heading floating nearer the previous paragraph. The margins are reversed. Set margin-top: 2em and margin-bottom: 0.5em, and add h2 + p { margin-top: 0; } so the next paragraph adds no extra gap. Afterward, measure the actual gap in the browser's box inspector, because margins can collapse, and rerun the squint test at a narrow width.
Exercise
Your captions use light gray text to sit below body text in the hierarchy. A checker reports a 3.2:1 contrast ratio on a white background. Does this pass WCAG AA, and how would you keep captions lower in rank?
Show answer
It fails. Normal-size text needs 4.5:1 at level AA, and captions are normally small text. Darken the gray until it reaches at least 4.5:1, then keep the captions lower in rank by using a smaller step on the type scale, or a lighter weight, or more space around them, not by lowering contrast.