Key takeaways
- Contrast ratio compares the relative luminance of two colors, from 1:1 to 21:1.
- AA asks for 4.5:1 for normal text and 3:1 for large text and interface components.
- AAA asks for 7:1 for normal text and 4.5:1 for large text.
The contrast ratio in the Web Content Accessibility Guidelines (WCAG) is a single number that says how different two colors are in brightness. Understanding how it is calculated makes it easier to fix a failing pair instead of guessing.
The formula
The ratio compares the relative luminance of the lighter color (L1) with that of the darker color (L2):
contrast = (L1 + 0.05) / (L2 + 0.05)
The result runs from 1:1 (identical colors) to 21:1 (black on white).
Relative luminance
Luminance measures how bright a color appears. First, each red, green and blue channel is converted from 0 to 255 to a 0 to 1 value, and then linearized so that it matches how screens emit light. Finally, the channels are weighted by how sensitive the eye is to each one:
L = 0.2126 × R + 0.7152 × G + 0.0722 × B
Green counts the most and blue the least, which is why a saturated blue can look dark even at full intensity.
A worked example
White has a luminance of 1. Gray #767676 has a luminance of about 0.18. The ratio is (1 + 0.05) / (0.18 + 0.05), which is roughly 4.54:1. That is just above the 4.5:1 needed for AA body text, which is why #767676 is often quoted as the lightest gray that passes on white.
The thresholds
For AA, normal text needs 4.5:1 and large text needs 3:1. For AAA, normal text needs 7:1 and large text needs 4.5:1. Large text means roughly 24px regular or 18.66px bold and up. WCAG 2.2 also asks for 3:1 for user interface components and graphics, such as input borders and icons.
Practical tips
Check every state, not just the default: hover, focus, disabled and error colors all count. Remember that text over images and gradients needs checking at its worst spot. Use the contrast checker to test a pair, or look at the contrast section on any color page to see how it performs against white and black.