Sub topic 11
Checking your hierarchy
This chapter is a review procedure for the work from the earlier chapters. It assumes you can read basic HTML and CSS, and that you have built headings, body text, captions, and labels with a type scale defined as custom properties. Here you check the result with a fixed routine, in a fixed order, so you catch problems before users do.
Why review as a separate step
A hierarchy can fail in ways that are invisible while you build it. The page may look right in your browser, at your zoom level, on your monitor, with your eyes. The HTML structure can still be wrong. The colors can still fail on a dim laptop screen. The text can still stop scaling when someone changes their default font size.
Review splits into three questions:
- Does the page look ordered to a person who glances at it?
- Does the markup describe the same order to software, such as screen readers and search engines?
- Does the hierarchy survive changes in color perception, zoom, font settings, and screen width?
Each question gets its own checks below. Do them in this order. Structural problems are cheaper to fix before you tune colors and sizes.
Check 1: The squint test
Open the page, then squint or blur your eyes until you can no longer read the words. You should still see the structure:
- The page title is the most prominent shape.
- Section headings form a clear second tier.
- Body text reads as an even gray texture of consistent blocks.
- Captions and other secondary text sit quietly below the body in prominence.
If two levels blur together, the difference between them is too small. The usual fix is to adjust size, weight, or spacing so each level differs from its neighbor in at least one clear way. Heading spacing matters here. A heading that has the same space above and below looks detached from its content. A common rule is more space above a heading than below it, so the heading visually belongs to the text that follows.
You can also do this in the browser. Add a temporary rule in DevTools:
html {
filter: blur(4px);
}Remove it when you are done. It is a review aid, not part of the design.
Check 2: The heading outline
The squint test checks what sighted users see. The outline check shows what assistive technology sees. Screen reader users often navigate by jumping from heading to heading, so the list of headings works like a table of contents.
A correct outline has these properties:
- Exactly one
h1that names the page. - No skipped levels going down. An
h2may be followed by anh3, but not by anh4. - Going back up is fine. An
h3can be followed by anh2when a new section starts. - Heading level reflects structure, not size. If you want a smaller
h2, change the CSS and keep the element.
You can inspect the outline with browser accessibility tools, or run a short script in the DevTools console. This script prints an indented outline and marks any skipped level:
const headings = document.querySelectorAll("h1, h2, h3, h4, h5, h6");
let previous = 0;
headings.forEach((el) => {
const level = Number(el.tagName[1]);
const skipped = previous !== 0 && level > previous + 1;
const indent = " ".repeat(level - 1);
const text = el.textContent.trim();
console.log(`${indent}h${level}: ${text}${skipped ? " <-- skipped level" : ""}`);
previous = level;
});
const h1Count = document.querySelectorAll("h1").length;
if (h1Count !== 1) {
console.warn(`Expected one h1, found ${h1Count}`);
}Run it on the Trail Guide example from earlier. The output should be an h1, two h2 headings, and one h3 under the second h2, with no warnings.
Read the printed outline as if it were the whole page. Each heading should make sense on its own, and the order should tell a coherent story. Headings such as "More" or "Details" pass the level check but fail this one.
Edge cases in the outline
- Headings inside components. A card component that always renders an
h3can end up under anh1with noh2between them. Components that contain headings need a way to set their level, or the page needs to be designed so the default level fits. - Headings hidden with CSS.
display: noneremoves a heading from the outline for everyone. A visually hidden heading, kept in the accessibility tree, still appears for screen reader users. Check whether you want that. - Styled paragraphs that look like headings. A
<p>or<div>with large bold text will not show up in the outline at all. The script above will not catch this. Look for text that is visually a heading and make sure it appears in the printed list. - Headings used for size. The reverse problem is an
h4used for a small bold label because the default style looked right. The script cannot detect it. Read the outline and ask whether each entry is really a section title.
Check 3: Contrast
Contrast is the difference in brightness between text and its background. The Web Content Accessibility Guidelines (WCAG) set minimum contrast ratios for level AA:
| Text | Minimum ratio |
|---|---|
| Normal body text | 4.5:1 |
| Large text (about 24px, or about 18.66px if bold) | 3:1 |
| Placeholder and disabled text | Placeholders need the same ratio as other text. Disabled controls are exempt. |
Secondary text is where failures cluster. Designers lighten captions and helper text to push them down the hierarchy, and the gray goes too far. The #595959 caption color from the earlier example is deliberate: on white it gives about 7:1. A lighter #999999 on white gives only about 2.8:1, which fails.
You can check a pair of colors with the browser's color picker in DevTools, which shows the ratio. You can also compute it yourself. This Python script implements the WCAG formula:
def channel(value):
c = value / 255
return c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4
def luminance(hex_color):
hex_color = hex_color.lstrip("#")
r, g, b = (int(hex_color[i:i + 2], 16) for i in (0, 2, 4))
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b)
def contrast(foreground, background):
lighter, darker = sorted(
(luminance(foreground), luminance(background)), reverse=True
)
return (lighter + 0.05) / (darker + 0.05)
pairs = [
("#595959", "#ffffff", "caption"),
("#767676", "#ffffff", "lightest gray that passes AA"),
("#999999", "#ffffff", "too light for text"),
]
for fg, bg, name in pairs:
ratio = contrast(fg, bg)
verdict = "pass" if ratio >= 4.5 else "fail"
print(f"{name}: {fg} on {bg} = {ratio:.2f}:1 ({verdict} for normal text)")When you check contrast, remember these cases:
- Check every background the text can appear on, such as cards, banners, and hover states.
- Text over an image has no single background color. Add a solid or semi-opaque layer behind the text, then measure against the worst part of the image.
- Do not rely on color alone to separate levels. A caption that differs from body text only by color has no hierarchy for someone who cannot see that difference. Pair color with size or position.
Check 4: Resizing and zoom
Users change text size in two different ways, and you should test both.
Browser zoom scales everything. At 200% zoom, the layout should still work and no text should be clipped. At 400% zoom, which is equivalent to a 320 CSS pixel wide window, content should reflow into a single column without horizontal scrolling for ordinary text.
Default font size is a browser setting. Users with low vision often raise it. Text sized in rem follows it, and text sized in px does not. To test, change the default font size in browser settings to a large value, then reload the page. Compare the two results:
- Headings, body text, captions, and labels should all grow.
- The relative order should hold. A heading should still be larger than body text, and a caption should not become larger than the body.
- Nothing should overlap or be cut off. Fixed heights on buttons and containers are the usual cause.
This is why the type scale uses rem and why clamp() has rem bounds. A bound written in px would silently disable this behavior. A middle value in vw alone also ignores the user's setting, which is why the earlier example mixes rem and vw in the same expression.
There is also a text spacing check from WCAG 1.4.12. Some users apply their own stylesheet that increases spacing. Paste this into DevTools as a user-style simulation and confirm that nothing is clipped or overlapping:
* {
line-height: 1.5 !important;
letter-spacing: 0.12em !important;
word-spacing: 0.16em !important;
}
p {
margin-bottom: 2em !important;
}Fixed-height boxes and overflow: hidden are the common causes of failures here.
Check 5: Form labels
Labels are the easiest element to get half right. A label that looks correct on screen may not be connected to its input in the markup.
Three tests catch most problems:
- Click the label. The cursor should move into the field, or a checkbox should toggle. If nothing happens, the
forattribute and the inputiddo not match, or the label is not wrapping the control. - Tab through the form. Every control needs a visible label, and the label should stay visible after the user starts typing. A placeholder alone fails this because it disappears.
- Run a script that lists controls without an associated label:
const controls = document.querySelectorAll(
"input:not([type=hidden]):not([type=submit]):not([type=button]), select, textarea"
);
controls.forEach((control) => {
if (!control.labels || control.labels.length === 0) {
console.warn("No associated label:", control);
}
});The script only recognizes labels made with <label>. A control named with aria-label is flagged even though it has an accessible name. That is intentional, because a visible <label> helps more users: it provides a larger click target and keeps the name on screen.
Also check the label styling against the rest of the hierarchy. A label should read as the name of a field. It should not compete with headings. If your labels look as strong as your h3 headings, reduce their weight or size.
Common failures and where to look
| Symptom | Likely cause | Check |
|---|---|---|
| Heading looks right but is missing from the outline | Styled `<div>` or `<p>` | Heading outline |
| Outline jumps from `h2` to `h4` | Level chosen for appearance | Heading outline |
| Captions are hard to read on a phone outside | Gray too light | Contrast |
| Text does not grow when browser font size changes | Sizes set in `px` | Resizing |
| Text overlaps after zoom | Fixed height or `overflow: hidden` | Resizing and spacing |
| Clicking a label does nothing | `for` does not match `id` | Form labels |
| Two heading levels look the same | Scale steps too close | Squint test |
A short review checklist
Use this list at the end of every page you build:
- Blur the page. Can you still pick out title, sections, body, and secondary text?
- Print the heading outline. One
h1, no skipped levels, each heading meaningful. - Measure the contrast of body text, captions, labels, and link text against their real backgrounds.
- Set a larger default font size and zoom to 200% and 400%. Confirm nothing is lost or overlapped.
- Click every label and tab through every field.
- Fix what failed, then run the checks again, because a fix to one level can disturb another.
Exercise
A page has an h1, followed by an h3 styled to look like a medium-sized section title, followed by an h2. The outline script reports "skipped level" on the h3. What are two correct ways to fix this, and why is changing the h3 to an h2 alone not enough?
Show answer
Change the h3 to an h2 so it follows the h1 directly, and keep the visual size by styling h2 with the size you want. Alternatively, keep the h3 only if an h2 genuinely precedes it, which here means reordering or adding the parent section. Changing the element only fixes the level. You must also check that the CSS gives the new h2 the same look as before, and that the following h2 still represents a section of equal rank. The look belongs in CSS, not in the choice of heading level.
Exercise
A caption uses color #aaaaaa on a white background and font-size: 12px. A review finds that it fails contrast and does not respond to the browser's default font size. List the changes you would make, and say which check each one satisfies.
Show answer
Change the color to one that reaches at least 4.5:1 on white, such as #595959 (about 7:1) or #767676 (about 4.5:1), which satisfies the contrast check. Change the size from 12px to 0.875rem so it scales with the user's default font size, which satisfies the resizing check. Keep it smaller than body text so it stays secondary, which satisfies the squint test. Then rerun all three checks, since changing the color or size can alter how the caption compares with the body text.
Exercise
A form field shows the text "Email" above an input, but clicking the text does nothing, and the label script prints "No associated label" for that input. What is the most likely cause, and what is the fix?
Show answer
The text is not a label element, or its for attribute does not match the input's id. Use <label for="email">Email</label> and give the input id="email", or wrap the input inside the label. After the fix, clicking the text should focus the field and the script should print no warning for it.