How contrast ratio is calculated
Each color is converted to relative luminance L: channels are linearised (c ≤ 0.04045 ? c/12.92 : ((c+0.055)/1.055)^2.4) and weighted 0.2126 R + 0.7152 G + 0.0722 B. Then:
ratio = (L_lighter + 0.05) ÷ (L_darker + 0.05)
The result runs from 1:1 (identical) to 21:1 (black on white).
WCAG 2 thresholds
| Content | AA | AAA |
|---|---|---|
| Body text | 4.5:1 | 7:1 |
| Large text (≥ 24px, or ≥ 18.66px bold) | 3:1 | 4.5:1 |
| Icons, borders of inputs, focus rings | 3:1 | — |
Examples
| Text | Background | Ratio |
|---|---|---|
#000000 | #ffffff | 21.00:1 |
#767676 | #ffffff | 4.54:1 |
#ffffff | #2563eb | 5.17:1 |
#ffffff | #e11d48 | 4.70:1 |
#ffffff | #16a34a | 3.30:1 |
#000000 | #facc15 | 13.71:1 |
#ffffff | #f59e0b | 2.15:1 |
#767676 is the lightest gray that passes AA on white.