How do you calculate a WCAG contrast ratio?
First convert the red, green and blue sRGB values to linear light. Use the weighted sum to find each color's relative luminance. Divide the lighter luminance plus 0.05 by the darker luminance plus 0.05. The result ranges from 1:1 for identical colors to 21:1 for black and white.
Contrast ratio = (lighter luminance + 0.05) ÷ (darker luminance + 0.05).
WCAG 2.2 defines relative luminance using weights 0.2126 for red, 0.7152 for green and 0.0722 for blue. An sRGB channel at or below 0.04045 is divided by 12.92. Above that value, apply ((channel + 0.055) ÷ 1.055)2.4.
What contrast ratio passes AA and AAA?
| Use | AA | AAA |
|---|---|---|
| Normal text | 4.5:1 | 7:1 |
| Large text | 3:1 | 4.5:1 |
| Relevant non-text components | 3:1 | — |
WCAG's large text threshold is generally at least 18 pt, or 14 pt bold, with equivalent size considerations for some fonts. See the W3C guidance for AA text contrast, AAA text contrast and non-text contrast. For a control or graphic, compare each color that conveys necessary information against its adjacent colors.
Why does #777 on white fail AA for normal text?
#777777 on #FFFFFF gives about 4.478:1, below the 4.5:1 minimum. Rounding it to one decimal place would hide that difference. #767676 on white gives about 4.542:1 and meets the threshold. The calculator checks pass or fail using the full calculated ratio.
Which colors should you enter?
Use the final opaque foreground and background colors visible in the interface. For transparency, gradients or imagery, determine the rendered colors in the relevant state first and check the weakest pair. Passing a color-pair threshold leaves other requirements, such as use of color, keyboard focus and readability, to the actual page review.