Light gray text on a white page looks elegant and is hard to read. The color contrast calculator takes the RGB values of a text color and a background color and gives the WCAG contrast ratio, the relative luminance of each color and whether the pair passes AA and AAA for normal and large text.
How the calculation works
- Linear value of each channel: divide the 0 to 255 value by 255. If the result is 0.04045 or less, divide it by 12.92. Otherwise, add 0.055, divide by 1.055 and raise it to the power 2.4. This undoes the gamma curve of sRGB.
- Relative luminance L = 0.2126 × red + 0.7152 × green + 0.0722 × blue, using the linear values. Green weighs the most because the eye is most sensitive to it.
- Contrast ratio = (L of the lighter color + 0.05) ÷ (L of the darker color + 0.05), from 1:1 for two identical colors to 21:1 for black on white.
- WCAG 2 levels: AA needs 4.5:1 for normal text and 3:1 for large text (18 pt, or 14 pt bold) and for interface parts such as icons and input borders. AAA needs 7:1 for normal text and 4.5:1 for large text.
Example
Gray text of rgb(102, 102, 102), which is #666666, on a white background. The linear value of 102 is ((0.4 + 0.055) ÷ 1.055)^2.4 ≈ 0.1329, so the luminance of the text is 0.1329 and that of white is 1. The ratio is (1 + 0.05) ÷ (0.1329 + 0.05) ≈ 5.74:1. It passes AA for normal text, which needs 4.5:1, but not AAA, which needs 7:1.
Why it matters
Accessible contrast helps people with low vision, people who use a screen in bright sunlight and everybody who reads on a small device. In many places, public sites and apps must meet WCAG AA, and a contrast check is one of the fastest ways to find a problem.
Good to know
Check every pair of colors that carries meaning: body text, links, buttons, placeholders, disabled states and focus rings. Text over a photo or a gradient needs a check at its worst point. A ratio that passes is not the only requirement, since color should not be the only way to show an error or a state. The calculator uses RGB values from 0 to 255, which you can read from a hex code, for example #66 hex is 102.
Related tools
The screen size calculator relates a display’s size to its resolution and the golden ratio calculator is a classic tool for layout proportions.