How to check colour contrast on a live website
WCAG 2.2 contrast in plain words: the ratios to hit, why a design file is not enough, how to check every text, state and icon on a real page, and how to fix what fails without changing your brand.
By Swapnil Gupta · · 8 min read
Low-contrast text is the most common accessibility failure on the web. WebAIM's yearly scan of a million home pages finds it on about four in five of them, year after year. It is also one of the easiest to fix, once you can see where it is.
This guide covers the numbers WCAG 2.2 asks for, why checking colours in a design file is not enough, how to check a real page including its hover and focus states, and how to fix a failing colour without changing the look of the brand.
The numbers to hit#
Contrast is a ratio between the lightness of two colours, from 1:1 (the same colour) to 21:1 (black on white). WCAG works it out from each colour's relative luminance as (L1 + 0.05) / (L2 + 0.05), the lighter colour on top. Level AA is the level laws and contracts usually ask for. Each row names the WCAG 2.2 success criterion it comes from:
| What | AA | AAA |
|---|---|---|
| Body text | 4.5:1 (1.4.3) | 7:1 (1.4.6) |
| Large text: 24px, or 18.66px bold | 3:1 (1.4.3) | 4.5:1 (1.4.6) |
| Parts of controls and graphics needed to use or understand them: input borders, meaningful icons, chart lines | 3:1 against the colours next to them (1.4.11) | No extra level |
| Focus indicator | Must be visible (2.4.7). Where its colour is what shows it, 1.4.11's 3:1 applies | At least the area of a 2px outline, and 3:1 between focused and unfocused (2.4.13) |
| Logos, inactive controls, decoration | Exempt | Exempt |
Why check the live page, not the design file#
A design file holds the colours someone chose. The page holds the colours a visitor sees, and they are often not the same:
- Transparency blends. Text at 60% opacity, or a background of
rgb(0 0 0 / 0.4), takes its real colour from whatever sits behind it. - Text sits on pictures. A headline over a photo can pass on its dark half and fail on its light half.
- Colours are inherited and overridden. A link inside a card on a tinted section may not be the colour the style guide gives links.
- States change colour. Hover, focus, visited and selected states each have their own pair of colours, and design files rarely show them all.
- Dark mode is a second page. Every pair has to pass again in the other theme.
- Third-party parts bring their own colours: cookie banners, chat widgets and embeds.
How to check a page, step by step#
One element, in DevTools
- Right-click the text and choose Inspect.
- In Chrome or Edge, the tooltip that appears on hover shows its contrast, with a mark when it passes. For the full ratio, open the Styles pane and click the colour swatch beside
color: the colour picker shows the ratio and draws the AA and AAA lines on the colour area. - In Firefox, open the Accessibility panel and choose Check for issues, then Contrast.
DevTools is exact for one element in one state. A page has hundreds of text elements, and Lighthouse's audit, which scans them all, sees only the default state of what is on the page when it loads.
The whole page, with Nitpique
- Turn Nitpique on and open the side panel's Page tab.
- Choose Accessibility, then Contrast, and pick Selection (one element and its children) or Visible page.
- Read the list worst first, and select a row to find its element on the page.
- Press Fix beside a failure to copy the nearest colour that passes.
It checks against WCAG 2.2, and against APCA (below) as a second opinion; APCA is not a WCAG 2.2 requirement. The contrast docs cover each option.
Hover, focus and disabled states#
WCAG applies to every state a visitor can see, not only the one on screen when the page loads. The state that fails is often not the default: a hover that lightens a button, or a focus ring in a pale tint of the brand.
- Hover and active: the text must still reach 4.5:1 (or 3:1 if large) against the new fill.
- Focus: at AA the indicator must be visible (2.4.7), and where its colour is what makes it visible, it needs 3:1 against the colours next to it (1.4.11). At AAA, 2.4.13 also sets a minimum size and a 3:1 change between the focused and unfocused states. A pale ring on a white page fails 1.4.11 even when the button's text passes.
- Disabled: inactive controls are exempt, but a control that only looks disabled while still working is not.
Checking states by hand means forcing each one in DevTools (the :hov button in the Styles pane). Nitpique's Control states check does it for every control on the page and lists those that fail only in a state first.
Fixing a failure without changing the brand#
Most failures are fixed by changing lightness alone. Keep the hue and the saturation, and move the lightness until the pair passes: the colour still reads as the same colour, just a step darker (or lighter, on a dark background).
Billed yearly. Cancel any time from your account settings.
Billed yearly. Cancel any time from your account settings.
- Work in a colour space whose lightness matches the eye, such as OKLCH. Lowering
Lthere changes contrast predictably, where HSL's lightness does not. - Fix the token, not the element. If the grey comes from a design token, change the token and every use of it passes at once.
- For text on a brand colour, it is often easier to darken the background a step than to change the text.
/* Before: 3.06:1 on white */
--text-muted: #8a94a6;
/* After: 4.64:1 on white, same hue */
--text-muted: #6b7588;What about APCA?#
APCA (the Accessible Perceptual Contrast Algorithm) is the method proposed for WCAG 3. It reports a lightness contrast, Lc, instead of a ratio, and it accounts for what WCAG 2 ignores: the text's size and weight, and whether it is dark on light or light on dark. It is noticeably more accurate for dark themes, where WCAG 2's formula can pass pairs that are hard to read.
APCA is not a WCAG 2.2 success criterion: passing it does not make a page conform, and failing it does not make a page fail. WCAG 3 is still a draft, so laws and audits ask for WCAG 2.2 AA. Pass WCAG 2.2 first, and use APCA as a second opinion, especially for dark mode and thin or small type.
A contrast checklist#
- Body text reaches 4.5:1 and large text 3:1, in light and dark themes.
- Placeholder text and helper text pass too: they are text.
- Links pass against the text around them and against their background.
- Hover, focus, active and visited states pass, not only the default.
- Input borders, meaningful icons and colour-only focus indicators reach 3:1 against what is next to them (1.4.11).
- Every control shows a visible focus indicator when reached with the keyboard (2.4.7).
- Text over images or gradients passes at its lightest point.
- Text with opacity or on translucent backgrounds is checked as rendered.
- Fixes go into design tokens, so they hold across the site.