Color Contrast: Meeting WCAG Without Ugly Design
Contrast is a measurable accessibility requirement. Learn the ratios, the WCAG levels, and how to fix a failing colour without ruining it.
By Velloreth
The requirement
WCAG defines a minimum contrast ratio between text and its background.
| Level | Normal text | Large text |
|---|---|---|
| AA | 4.5:1 | 3:1 |
| AAA | 7:1 | 4.5:1 |
A non-text element such as an icon, a border, a chart line or a focus indicator needs 3:1.
The ratio is a measurement, not an opinion. It is computed from the colours.
Large text
Large text is:
- 18pt or larger, which is about 24px
- 14pt or larger when bold, which is about 18.66px
The threshold is lower because a larger glyph is easier to read at a lower contrast.
A common mistake: treating 18px as large text. It is not, unless it is bold.
The calculation
The ratio is computed from the relative luminance.
L = 0.2126 R + 0.7152 G + 0.0722 B
ratio = (L1 + 0.05) / (L2 + 0.05)
Where L1 is the lighter colour and L2 the darker.
The range: 1:1 for identical colours, 21:1 for black on white.
The luminance is not the average of the channels. The green channel contributes the most, because the eye is most sensitive to it. This is why a pure blue and a pure green with the same hex brightness have very different luminances.
A tool does the arithmetic. The point is to know that the ratio is a property of the two colours, not of the design intent.
Common failures
Grey text on white. #999 on #fff is 2.85:1, which fails AA.
A brand colour as text. A bright brand colour often fails on white.
Placeholder text. It is usually too light, and it is text a user must read.
A link in body text. It must be distinguishable, and the contrast must pass.
A focus ring. It needs 3:1 against the adjacent colours.
A chart line. It needs 3:1 against the background.
A border on an input. It needs 3:1, because it is the visual boundary of the control.
Text on an image. The effective background varies, so a solid overlay is needed.
Fixing a failure
Darken the text. The simplest fix, and it usually keeps the palette.
Lighten the background. A near-white background instead of pure white.
Shift the hue. A grey that fails can pass by moving it toward the background’s hue, which keeps the perceived colour.
Add a background block. A solid background behind the text, which is common for text on an image.
Increase the weight or the size. A larger or bolder text has a lower threshold.
Use a border instead of a colour. A border can carry the meaning that a colour was carrying.
Do not rely on colour alone. A link that is only distinguished by colour fails a different criterion. Add an underline.
The tools
A browser devtools shows the contrast ratio for a selected element, and it flags a failure.
A contrast checker takes two colours and returns the ratio.
Lighthouse reports a contrast failure in the accessibility audit.
axe reports the specific elements that fail.
A design token system can enforce a passing pair, so a new colour is checked at the source.
Designing with contrast
Define a text colour per background. A token such as text-on-surface and text-on-primary, so a component does not pick a colour.
Test the palette as a matrix. Every text colour against every background it appears on.
Prefer a darker text on a light background. It is easier to pass and it is the common convention.
Reserve the low-contrast pair for a large heading. A large text has a lower threshold.
Check the dark mode separately. A palette that passes in light mode can fail in dark mode.
The limits of a checker
A checker measures two colours. It does not know about:
- A background image
- A gradient
- A semi-transparent overlay
- A text shadow
- A video
The effective background is what matters. A text over a photo has a different background at every point.
The fix: a solid or semi-transparent overlay behind the text, and a check of the worst case.
A checker also does not know the intent. A decorative element is exempt, and a meaningful one is not.
Common mistakes
Treating 18px as large text. It is not, unless it is bold.
Checking only the body text. A placeholder, a caption and a link all need a check.
Ignoring the non-text elements. An icon, a border and a focus ring need 3:1.
Relying on colour alone. A link needs a second cue.
A checker pass with a background image. The effective background is not the one that was checked.
Forgetting dark mode. The palette is a second set of pairs.
A disabled control that is unreadable. It is exempt, and it should still be legible.
A focus ring that is invisible. It is the most important non-text element for a keyboard user.
A quotable summary
WCAG AA requires a contrast ratio of 4.5:1 for normal text and 3:1 for large text, and AAA requires 7:1 and 4.5:1. Large text is 18pt or 14pt bold, which is about 24px or 18.66px, and a non-text element such as an icon, a border or a focus ring needs 3:1. The ratio is computed from the relative luminance, and a checker measures two colours, so a background image or a gradient needs a separate check of the worst case.
Related reading
For the broader topic, see aria-labels-explained and css-grid-complete-guide. For the related guides, css-custom-properties and css-units-explained.