Sub topic 12
Checking your work: squint test and contrast checks
This chapter assumes you know basic HTML and CSS, including custom properties and the box model. It also assumes you have read the earlier chapters on size, contrast, position, and combining cues. Here you will learn how to test a finished page and find hierarchy problems before your readers do.
Why you need a check step
A hierarchy can look right to you and still fail for other people. You know the page well, so you already know where to look. A first-time visitor does not. Your monitor, your eyesight, and your room lighting are also not the same as theirs.
Two checks cover most problems:
- The squint test is a quick, human judgment of what the eye is drawn to.
- Contrast checks are measured numbers that tell you whether text and controls are readable.
The first catches competing emphasis. The second catches unreadable or hard-to-see elements. Neither replaces the other.
The squint test
The squint test removes detail so that only the strongest cues remain. Fine text becomes unreadable, but large shapes, dark and light areas, and groups of content are still visible. What you can still see is what your hierarchy actually emphasizes.
How to run it
- Open the page at a realistic window size, for example 1280 px wide for desktop and 390 px wide for a phone.
- Lean back, or squint until the text is blurry. You can also zoom the browser out to 25–30%.
- Without reading anything, name the first, second, and third things you notice.
- Write those three down. Compare them with what you intended.
- Repeat for each distinct view: home page, article, form, and so on.
What to look for
| Observation | Likely cause | Fix |
|---|---|---|
| The first thing you notice is not the main heading or main action | A decorative image, banner, or bright color outranks it | Reduce the competing element's size, saturation, or contrast |
| Several elements seem equally strong | Too many cues applied to too many items | Choose one primary element and tone the others down |
| Nothing stands out; the page looks flat | Sizes and weights are too close together | Widen the type scale steps or add weight and contrast to the primary element |
| Related items look scattered | Spacing between them is uneven | Tighten spacing inside groups and enlarge gaps between groups |
| The primary button looks the same as the secondary one | Both use the same fill and weight | Give only one a filled background |
Blurring more precisely
Squinting is subjective. For a repeatable version, apply a blur to the page in your browser's developer tools. This temporary rule can be pasted into the console or into a DevTools style override:
html {
filter: blur(4px);
}Adjust the radius until body text is unreadable but headings and buttons are still visible as shapes. Remove the rule afterward. Do not ship it.
Another variation is a grayscale filter, which removes color so you can see whether the hierarchy depends on hue alone:
html {
filter: grayscale(1);
}If the primary button only stands out because it is blue, and in grayscale it looks like everything else, you are relying on hue. Readers with color vision deficiency, or anyone using a monochrome display, will lose that cue. Add a difference in value (lightness) or weight.
Limits of the squint test
- It reflects your own perception. Ask one or two other people to do it and compare answers.
- It says nothing about whether text is readable at full size.
- It does not check keyboard order or screen reader order. Those need separate checks, covered later in this chapter.
Contrast checks
The WCAG contrast ratio expresses how different two colors are in relative luminance, from 1:1 (identical) to 21:1 (black on white). The earlier chapter on WCAG ratios explained the formula. Here the focus is on applying it as a routine check.
Required thresholds
| Element | Minimum ratio (WCAG AA) | Stricter level (WCAG AAA) |
|---|---|---|
| Normal body text | 4.5:1 | 7:1 |
| Large text (at least 24 px, or 18.66 px bold) | 3:1 | 4.5:1 |
| UI components and meaningful graphics (borders of inputs, icons that carry meaning, focus indicators) | 3:1 | not defined |
Most teams target AA as the floor. Logos and purely decorative elements are exempt from these requirements. Disabled controls are also exempt, but a disabled state should still be recognizable.
Computing a ratio in code
The function below implements the WCAG formula. Running it on your own color pairs is useful when you want to check an entire palette at once.
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])); // 21You can extend this into a small audit that reports pass or fail for every text and background pair you use:
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);
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
}
function hexToRgb(hex) {
const n = parseInt(hex.slice(1), 16);
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
}
const pairs = [
{ name: "Body text", fg: "#1f2933", bg: "#ffffff", min: 4.5 },
{ name: "Primary button label", fg: "#ffffff", bg: "#0b57d0", min: 4.5 },
{ name: "Secondary button border", fg: "#0b57d0", bg: "#ffffff", min: 3 },
{ name: "Placeholder text", fg: "#9aa5b1", bg: "#ffffff", min: 4.5 },
];
for (const pair of pairs) {
const ratio = contrastRatio(hexToRgb(pair.fg), hexToRgb(pair.bg));
const status = ratio >= pair.min ? "PASS" : "FAIL";
console.log(`${status} ${ratio.toFixed(2)}:1 (needs ${pair.min}) ${pair.name}`);
}The placeholder pair is a common failure. Light gray placeholder text looks tidy, but it often falls below 4.5:1 against white.
Tools for checking in the browser
You do not have to compute every ratio by hand. Use these in your normal workflow:
- Browser DevTools. Inspecting a text element shows its contrast ratio in the color picker, with markers for the AA and AAA thresholds.
- An automated accessibility scanner such as Lighthouse or axe. It reports every text element that fails.
- A standalone contrast checker, where you type two colors and read the ratio.
Automated tools have blind spots. They cannot reliably measure text over images, gradients, or semi-transparent layers. For these, check the worst-case spot: the point where text sits over the lightest part of a dark image, or the darkest part of a light one.
Common contrast mistakes
- Judging by eye on a bright, high-quality monitor. A pair that looks fine on your screen can fail outdoors or on a cheap display.
- Checking the default state only. Check hover, focus, active, visited link, and error states too.
- Forgetting text over images. Add a solid or gradient overlay behind the text, then measure against the overlay.
- Using opacity to create secondary text. Lowering opacity blends the text toward the background, so the ratio drops. Pick an actual color and measure it.
- Relying on color alone. A red error message is not enough. Add an icon or text such as "Error:" so the meaning survives without color.
Putting the two checks together
The checks answer different questions, so run them in sequence.
Order matters. If you fix contrast first, you may then change emphasis in the squint test and break the colors you just fixed. Settle the hierarchy first, then verify the numbers.
Checking order for keyboard and screen reader users
A hierarchy that works visually can still fail if the HTML order does not match. The earlier chapter on source order explained why. As part of your review, do this:
- Put the mouse aside and press Tab repeatedly. Focus should move in the same sequence your eyes would follow, and the focus indicator must be visible each time.
- Look for focus jumping to a distant part of the page. This often happens when CSS
order, grid placement, or absolute positioning has rearranged the content. - Turn off CSS (or use a reading-mode view). The content should still make sense, with the main heading first and related items together.
- Optionally, use a screen reader and listen to the heading list. Heading levels should follow the visual levels.
Checking at different sizes
Run both checks at least at a narrow and a wide viewport. A layout that puts the primary action beside the heading on desktop may push it far below the fold on a phone. Also try:
- Browser zoom at 200% and at 400%, because many readers enlarge text.
- A larger default font size in browser settings, to make sure your
rem-based type scale still holds. - Both light and dark themes, if you offer them. Each theme needs its own contrast check.
A short review checklist
- The squint test shows one clear primary element per view.
- The second and third things noticed match the intended reading order.
- Removing color (grayscale) does not erase the hierarchy.
- Body text has at least 4.5:1 contrast; large text and UI components at least 3:1.
- Hover, focus, error, and disabled states were checked too.
- Tab order follows the visual order.
- The layout holds at narrow, wide, and zoomed sizes.
Exercises
Exercise
You blur your landing page and the first thing you notice is a large, bright decorative illustration instead of the heading and the "Sign up" button. Name two ways to fix this without removing the illustration.
Show answer
Reduce the illustration's competing cues, for example make it smaller, lower its saturation or contrast, or move it away from the first-read area. Also strengthen the primary elements by enlarging the heading or giving the "Sign up" button a filled, high-contrast background. The goal is for the heading and button to outrank the illustration in the blurred view.
Exercise
A designer sets secondary text to #767676 on a white background and says it passes. Using the thresholds in this chapter, what ratio does it need if it is 16 px normal-weight text, and why might it still fail on a gray card background such as #f0f0f0?
Show answer
It needs at least 4.5:1 for AA, because 16 px normal-weight text is not large text. #767676 on white is just above 4.5:1. On a darker card such as #f0f0f0, the background is less luminous, so the ratio falls below 4.5:1 and the text fails. Always measure against the actual background the text sits on.
Exercise
Your page passes every contrast check, but pressing Tab moves focus from the header to the footer links and then back up to the main content. Which check found this problem, and what is the likely cause?
Show answer
The tab-order check found it. The likely cause is that CSS (such as grid placement, flex order, or absolute positioning) rearranges the visual layout so it no longer matches the DOM order. Fix it by reordering the HTML to match the visual sequence.