Web Accessibility - Color Contrast
Color Contrast
Contrast is the difference in brightness between text and its background. Low contrast, like light gray text on white, is hard to read for many people.
Contrast is measured as a ratio, from 1:1 (no difference) to 21:1 (black on white).
How Much Contrast is Enough?
The Web Content Accessibility Guidelines (WCAG) set these minimums at level AA:
| Content | Minimum ratio |
|---|---|
| Normal text | 4.5:1 |
| Large text (24px, or 18.66px bold) | 3:1 |
| Buttons, form borders, icons, focus outlines | 3:1 |
Examples on a white background:
| Text color | Ratio | Result |
|---|---|---|
| #000000 (black) | 21:1 | Passes |
| #767676 (gray) | 4.5:1 | Passes, just barely |
| #999999 (light gray) | 2.8:1 | Fails |
Do not Use Color Alone
Some people cannot tell certain colors apart, like red and green. Always add text or an icon too:
Example
<!-- Avoid: only color shows the error -->
<input style="border-color:
red">
<!-- Better: color + text -->
<input
aria-describedby="emailError" style="border-color: red">
<p
id="emailError">Please enter a valid email address.</p>
Check your Contrast
You do not have to calculate it yourself. Browser developer tools show the contrast ratio when you inspect text, and many free online contrast checkers do the same.