Colour contrast for accessibility: WCAG AA and AAA in practice
Colour contrast for accessibility comes down to one number: the ratio between the relative luminance of two colours. WCAG AA asks for at least 4.5:1 for normal text, 3:1 for large text and 3:1 for interface components; AAA raises text to 7:1. This guide shows how the ratio is calculated, with the arithmetic, and how I fix a pair that fails.
You can test any pair instantly in the colour picker: it shows the exact ratio, five AA and AAA badges and, for a failing pair, the closest colour that passes. Read on if you want to know why a pair passes or fails, and what to change.
WCAG AA and AAA thresholds
| What you are checking | AA | AAA |
|---|---|---|
| Normal text | 4.5:1 | 7:1 |
| Large text (18pt, or 14pt bold) | 3:1 | 4.5:1 |
| UI components and graphics (borders, icons, focus rings) | 3:1 | no separate level |
The AA text rule is Success Criterion 1.4.3 and the non-text rule is 1.4.11; both are explained on the W3C’s Understanding Contrast (Minimum) page. Large text means 18pt, which is 24px, or 14pt bold, about 18.7px. Logos, brand names, inactive controls and purely decorative text are exempt. Black on white is 21:1 and any colour against itself is 1:1, so the whole scale runs from 1 to 21.
How the contrast ratio is calculated
The ratio is (L1 + 0.05) / (L2 + 0.05), where L1 is the relative luminance of the lighter colour and L2 of the darker one. Relative luminance is a weighted sum of linearised sRGB channels:
each channel c (0–1): if c ≤ 0.04045 then c / 12.92, else ((c + 0.055) / 1.055)^2.4
Green carries 72% of the weight and blue only 7%, which is why a saturated blue can look dark and a yellow can look bright at equal “brightness” in HSL. Worked example, white text on the strong blue #1d4ed8 (see the colour code guide for where 29, 78, 216 come from):
- Divide by 255: 0.1137, 0.3059, 0.8471.
- Linearise each: 0.0123, 0.0762, 0.6867.
- Weight and sum: 0.2126 × 0.0123 + 0.7152 × 0.0762 + 0.0722 × 0.6867 = 0.0026 + 0.0545 + 0.0496 = 0.1067.
- White has L = 1. Ratio = (1 + 0.05) / (0.1067 + 0.05) = 1.05 / 0.1567 = 6.70:1.
That passes AA for any text size, and misses AAA for normal text by a little. Dark ink #14213d on a pale #f3f7fb page comes out at 14.84:1, which clears everything.
The grey that just passes: #767676 and #777777
Designers often quote #767676 as the lightest grey that works on white. Check it. For #767676, each channel is 118 ÷ 255 = 0.4627, linearised to 0.1812. All three channels are equal, so L = 0.1812 and the ratio is 1.05 / 0.2312 = 4.542:1. It passes AA.
One step lighter, #777777, has channels of 119 ÷ 255 = 0.4667, linearised to 0.1845. The ratio is 1.05 / 0.2345 = 4.478:1. It fails.
This is why the W3C says the ratio must not be rounded. 4.478 does not become 4.5, and you may not claim a pass because a checker displays “4.5”. A good checker shows two decimals but compares the exact value, and when rounding would cross a threshold it shows more. The picker does this: #007BC8 on white is 4.4995:1, which it displays as 4.499:1 and marks as a fail, not as a misleading 4.50. I treat anything under 4.6 as a warning to look for a darker option rather than ship the minimum, because screens, glare and ageing eyes all take their cut.
Fixing a failing pair by changing lightness
Do not swap in a new colour. (The picker automates this: for a failing pair it offers the closest colour that passes AA, found by holding the OKLCH hue and chroma and moving only lightness.) Keep the hue and saturation and move lightness until the pair passes. That way the brand colour stays recognisable. Take a fresh green button label on white, hsl(160 84% 34%) = #0ea06f, which measures only 3.35:1. Lower L step by step:
| HSL lightness | HEX | Ratio on white | Result |
|---|---|---|---|
| 34% | #0ea06f | 3.35:1 | Fails normal text; passes 3:1 for large text and UI |
| 32% | #0d9668 | 3.76:1 | Fails normal text |
| 30% | #0c8d62 | 4.20:1 | Fails normal text |
| 29% | #0c885f | 4.47:1 | Fails by 0.03 |
| 28% | #0b835b | 4.76:1 | Passes AA |
| 26% | #0b7a55 | 5.34:1 | Passes AA with margin |
Notice 29%: 4.47 looks close enough and is not. The same job in OKLCH is quicker, because L tracks what you see. The green is oklch(62.22% 0.1333 162.27); hold the hue and chroma constant and lower only L, and the first lightness that reaches 4.5:1 is about 55.3%, which is #00875D at 4.54:1. That is what the picker suggests for this pair. The suggestion for #777777 on white is #767676.
If you cannot darken the background colour, flip the text. Dark navy #14213d on the original green #0ea06f gives 4.77:1, so a green button with dark text passes where white text on the same button does not (3.35:1). Many brands find dark-on-bright looks fresher anyway.
Large text, UI components and the other 3:1 rule
- Large text needs only 3:1 at AA. A heading at 24px or more in
#949494(3.03:1 on white) passes; the same colour for body text fails. - Form field borders, icons that carry meaning, chart lines and focus rings need 3:1 against whatever is next to them. A pale grey input border that looks neat is often under 2:1, which makes the field hard to find.
- States count. Hover, focus, selected and disabled-looking-but-active states are checked separately. Truly inactive (disabled) controls are exempt.
- Text on images has no single background. Put a solid or semi-opaque panel behind it and test against the lightest part of the image that the text covers.
- Transparent colours must be flattened first: test the colour as it appears on the real background, not the number in the stylesheet. The picker does this for semi-transparent text, blending it over the background before it measures;
#1D4ED880on white becomes#8EA6EBand scores only 2.39:1.
My routine for checking a palette
- List the pairs that actually occur: body text on page, text on card, link on page, button label on button, border on card, placeholder on field.
- Test each pair with exact values. Pick them from a design file or screenshot with care, as the guide to picking colours from an image explains, because a JPEG pixel can be a few units off.
- For every failure, move lightness (not hue) in the colour you are allowed to change, and re-test. Note down the final HEX for the design tokens.
- Test dark mode as its own palette. A colour that passes on white often fails on near-black, and the reverse.
- Aim for 4.5:1 minimum on everything that is text, 7:1 for long reading text, and 3:1 on every border and icon that matters.
Contrast is necessary, not sufficient: it does not cover colour-only meaning (an error shown only in red), thin fonts or small sizes. Treat the ratio as the first gate, then judge legibility with your own eyes at the real size.
Things people ask
What contrast ratio does WCAG AA require?
4.5:1 for normal text, 3:1 for large text (18pt, or 14pt bold) and 3:1 for UI components and graphical objects such as input borders and icons.
What is the difference between WCAG AA and AAA?
AAA is stricter for text: 7:1 for normal text and 4.5:1 for large text. AA is the usual legal and practical target; AAA is worth aiming for on long reading text.
Does #777777 pass on white?
No. #777777 on white is 4.478:1, just under 4.5:1. #767676 is the lightest grey that passes, at 4.542:1.
Can I round 4.49 up to 4.5?
No. WCAG compares the exact ratio, so 4.499 does not meet 4.5:1. Show two decimals but compare the unrounded value.
How do I fix a failing colour pair?
Keep the hue and saturation and darken the lighter colour (or lighten the darker one) until the ratio passes. Alternatively flip the text colour to dark or white, whichever gives the higher ratio.