Sub topic 12
Checking your work: squint test and contrast checks
This chapter assumes you know basic HTML and CSS, and that you have read the earlier chapters on size, contrast, position, and combining cues. Here you will check a finished page in two ways: by eye with the squint test, and by number with WCAG contrast ratios.
Why check at all
A hierarchy that looks right to you may not work for a first-time visitor. You know the content, so your eye goes where you expect. Two quick checks reduce that bias. One tests what stands out. The other tests whether text can be read.
The squint test
The squint test shows which elements dominate when you can't read any detail.
- Open the page at a normal size.
- Lean back, or squint until the text blurs. You can also apply a blur in the browser's developer tools, or take a screenshot and blur it in an image editor.
- Note what you still notice. Write down the first, second, and third things your eye lands on.
- Compare your list with the order you intended.
You want the primary element, such as the main heading or the main button, to survive the blur. If a banner, an image, or a bright link wins instead, emphasis is competing.
/* Temporary: paste into devtools, or add and remove while testing */
body {
filter: blur(4px);
}Remove this rule when you finish. Blurring the page for real users hurts readability.
Common squint-test findings
| What you see | Likely cause | Fix |
|---|---|---|
| Several items equally strong | Too many emphasized elements | Reduce emphasis on all but one |
| Nothing stands out | Sizes and weights too similar | Widen the type scale steps or add a filled button |
| A decoration wins | Large or saturated image near the content | Mute it, shrink it, or move it |
| Primary button fades away | Outline style or low contrast | Use a filled background |
Contrast checks with WCAG ratios
The squint test is a judgment. Contrast ratios are measurements. WCAG (the Web Content Accessibility Guidelines) sets minimum ratios between text and its background:
- Normal text: at least 4.5:1 (level AA).
- Large text (about 24px, or 18.66px if bold): at least 3:1.
- UI components such as input borders and icons: at least 3:1 against adjacent colors.
The ratio runs from 1:1 (identical colors) to 21:1 (black on white). You can compute it yourself. This function follows the WCAG formula:
function channel(value) {
const s = value / 255;
return s <= 0.04045 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
}
function luminance([r, g, b]) {
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
}
function contrastRatio(colorA, colorB) {
const a = luminance(colorA);
const b = luminance(colorB);
const lighter = Math.max(a, b);
const darker = Math.min(a, b);
return (lighter + 0.05) / (darker + 0.05);
}
console.log(contrastRatio([0, 0, 0], [255, 255, 255])); // 21Try it on the primary button from the earlier chapter, white text on #0b57d0, which is RGB [11, 87, 208]:
// Add below the functions above
const ratio = contrastRatio([255, 255, 255], [11, 87, 208]);
console.log(ratio.toFixed(2), ratio >= 4.5 ? "passes AA" : "fails AA");The result is above 4.5, so the label is readable. In practice you will often use a browser tool instead. Chrome and Firefox developer tools show the ratio in the color picker, and many extensions scan a whole page.
A review checklist
- Squint at the page. Is the first thing you notice the thing that matters most?
- Check that only one primary element stands out in each view.
- Measure body text, headings, links, and button labels against their backgrounds.
- Measure borders and icons that carry meaning.
- Repeat at a narrow and a wide screen width.
Common errors
- Fixing contrast by darkening everything. The text passes, but the hierarchy flattens because every element is equally strong.
- Trusting your own screen. Check at a lower brightness, or on a different device.
- Treating 4.5:1 as a target for all text. Secondary text can sit just above the minimum, which leaves headings and primary actions room to be stronger.
- Relying on color alone to mark emphasis. Add weight, size, or an underline too.
Exercise
A page's secondary link text is #767676 on a white background. In the squint test, the link still draws more attention than the page heading. Name one check you would run on the link color, and one change you would make for the hierarchy.
Show answer
Compute or look up the contrast ratio of #767676 on white. It is about 4.5:1, right at the AA minimum for normal text, so it passes but cannot go lighter. The link competes with the heading, so reduce its emphasis through size, weight, or surrounding space. Alternatively, strengthen the heading with a larger step in the type scale or heavier weight. Do not lighten the link further, since that would fail contrast.
Exercise
Why should you run the squint test again after you change a color to meet a contrast ratio?
Show answer
Changing a color alters how strongly that element stands out. A darker or more saturated color can make a secondary element compete with the primary one, so the intended order may have changed.