Fixing color-contrast violations, and why some need review
Low contrast is the most common detectable problem on the web, and usually the cheapest to fix: one design token, changed once. Here is what the rule measures and where it has to give up.
What the rule checks
axe-core's color-contrast (opens in a new tab)
rule tests visible text against WCAG 2.2 success criterion
1.4.3 Contrast (Minimum) (opens in a new tab),
at level AA. It computes the foreground colour of each text node, works out the background
behind it, and compares the two as a contrast ratio between 1:1 (no difference) and 21:1
(black on white).
The thresholds:
- 4.5:1 for normal text.
- 3:1 for large text. WCAG defines large as at least 18 point, or at least 14 point and bold. In CSS pixels that is 24px, or about 18.66px bold.
Text that is part of an inactive control, purely decorative, invisible, or part of a logo is exempt. Disabled form controls are the case you will meet most often.
A typical result looks like this:
{
"rule": "color-contrast",
"impact": "serious",
"wcag": ["1.4.3"],
"selector": ".hero__subtitle",
"message": "Contrast ratio 3.03:1, needs 4.5:1"
}
Close is not a pass
The ratio is a hard line. The classic example is #777777 on white: 4.48:1, which fails
for body text. #767676, one step darker, is 4.54:1 and passes. Nobody can see the
difference between those two greys, which is exactly why a tool is better at this check
than a person squinting at a mock-up.
/* Before: 4.48:1 on white, fails for normal text */
.meta { color: #777; }
/* After: 4.54:1, passes */
.meta { color: #767676; }
Some other common pairs on a white background:
| Colour | Ratio on white | Normal text | Large text |
|---|---|---|---|
#999999 | 2.85:1 | Fails | Fails |
#949494 | 3.03:1 | Fails | Passes |
#6b7280 | 4.83:1 | Passes | Passes |
#595959 | 7.0:1 | Passes | Passes |
Buttons are the other common source: white text on a mid-blue such as #3b82f6 is
3.68:1, fine for a large heading and a failure for a 16px button label. #2563eb is
5.17:1.
Fix the token, not the element
Contrast failures cluster. A grey defined once in a design system and used in forty places produces forty violations and needs one fix. Before you touch any CSS, sort the findings by colour pair and you will usually find three or four values responsible for nearly all of them.
When the brand colour itself cannot change, change what sits next to it: darken the text, put the text on a solid panel, or reserve the brand colour for large text and non-text decoration where 3:1 or no requirement applies. Making text bigger only helps if it crosses the large-text threshold.
Why some results say "needs review"
axe-core sorts results into more than pass and fail. When it cannot work out the background colour with confidence, it reports the element as incomplete, meaning a person has to decide. The usual reasons:
- Background images. The text sits on a photo or a pattern, and the contrast varies pixel by pixel.
- Gradients. The ratio is different at each end.
- Overlapping elements. Something positioned on top of or behind the text makes the real background ambiguous.
- Pseudo-elements. A background painted by
::beforeor::afteris hard to resolve.
These are not violations, so a gate that fails on violations will not fail on them. That is the correct behaviour: failing a build on a guess would be wrong half the time. It also means a hero banner with text over a photograph can pass a scan and be unreadable. Check those by hand, at the narrowest and widest viewport, since the crop of the image changes.
A common fix for text on images is a solid or semi-opaque scrim behind the text. It gives the text a predictable background, which helps both readers and the rule.
What the rule does not cover
- Non-text contrast. 1.4.11 Non-text Contrast (opens in a new tab) requires 3:1 for the visible parts of controls and meaningful graphics: an input's border, a checkbox outline, an icon button, a focus indicator. axe-core has no rule for it, so a text field whose only boundary is a pale grey line will not be reported.
- States. The rule checks the page as rendered at the moment of the scan. Hover, focus and visited colours, and text that appears only after an interaction, are checked only if the scan sees that state.
- Colour alone. Using colour as the only way to convey information is
1.4.1 Use of Color (opens in a new tab).
axe-core's
link-in-text-blockrule covers one case of it (links distinguished from surrounding text only by colour). The rest needs a person. - AAA. The enhanced ratios of 1.4.6 (7:1 and 4.5:1) are checked by a separate rule,
color-contrast-enhanced, which is not part of the AA rule sets.
Keeping it fixed
Contrast regressions come back with every new component and every marketing page. Once you have fixed the tokens, a CI check that fails on new violations stops the forty-first low-contrast label from merging. The criteria table shows which perceivable criteria a scan can and cannot see, and what a scan does not tell you covers the rest.
Related
- Adding accessibility checks to a site that already has violations
- What automated testing can and cannot detect — WCAG 2.2 reference
- Free Accessibility Scan & WCAG Checker
Try it on your own site: scan a URL for free, or read the docs to add a baseline to your pipeline.