Developer
How to check color contrast for accessibility
By Amritanshu Kumar Gaurav · Published
Quick answer
Color contrast is the ratio between the lighter and darker of two colors, from 1:1 to 21:1. WCAG asks for at least 4.5:1 for normal text, 3:1 for large text, and 3:1 for buttons, icons and borders. To check it, enter your color in a contrast checker and read the ratio for white and black text on it. If it fails, keep the same hue and make it darker or lighter until it passes.
Why this matters
Low-contrast text is hard to read for people with low vision, for older readers, and for anyone using a phone in sunlight. It is also one of the most common accessibility failures on the web, and many accessibility laws point to WCAG AA. Brand colors are the usual cause: a bright orange or a light green looks great as a button but fails with white text on it.
What is a contrast ratio?
The contrast ratio compares the relative luminance (how bright a color looks to the eye) of two colors. It runs from 1:1, two identical colors, to 21:1, black on white. WCAG 2 defines three levels for text: AA needs 4.5:1, AAA needs 7:1, and large text needs only 3:1 at AA (4.5:1 at AAA). Interface parts such as buttons, form borders and icons need 3:1 against what is next to them.
How it works
A contrast checker turns each color into its relative luminance, a weighted sum of its red, green and blue light after undoing the sRGB gamma curve. Green counts most and blue least, because that is how the eye sees brightness. The ratio is (lighter + 0.05) divided by (darker + 0.05). Because it depends only on brightness, two very different hues, like red and green, can have almost no contrast.
Step by step
- 1Enter your brand color. Open the Contrast Checker and type or paste your color in any CSS format: HEX, RGB, HSL, OKLCH or a name like coral.
- 2Read white and black text. The checker shows white text and black text on your color, each with its ratio and whether it passes AAA, AA, large text only, or fails, plus the 3:1 result for interface parts.
- 3Check a second color if you need to. Open "Check against another color" to test a specific text or background color, and use the swap button to flip them.
- 4Fix a failing pair. If text fails 4.5:1, the checker suggests the closest shade of your color that passes. Copy it, or click Use this to check it.
WCAG 2 contrast minimums
| AA | AAA | |
|---|---|---|
| Normal text | 4.5:1 | 7:1 |
| Large text (24px, or 18.7px bold) | 3:1 | 4.5:1 |
| Buttons, icons, form borders | 3:1 | not defined |
Common mistakes
- Judging contrast by eye. Screens, brightness and your own eyes vary; the ratio does not.
- Forgetting placeholder text and disabled-looking grey text, which often fails even when body text passes.
- Putting text over a gradient or a photo and checking only one spot. Check the lightest part behind the text.
- Checking a semi-transparent color as if it were solid. Blend it over its real background first.
- Rounding up. A ratio of 4.49:1 fails AA, even though it looks like 4.5.
Best practices
- Check your brand colors once and write down which text color goes on each.
- When a brand color fails, keep its hue and change only its lightness, so it still looks like your brand.
- Use a darker shade for text and links, and keep the bright brand color for large areas and decoration.
- Check focus rings and form borders against the background at 3:1.
Frequently asked questions
Sources
- https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html
- https://www.w3.org/WAI/WCAG22/Understanding/contrast-enhanced.html
- https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html