How the WCAG contrast ratio is calculated
WCAG 2 defines contrast between two colours as (L1 + 0.05) / (L2 + 0.05), where L1 is the relative luminance of the lighter colour and L2 of the darker one. The result runs from 1:1, identical colours, to 21:1, black on white. The 0.05 terms model the small amount of ambient light reflected from any screen.
Relative luminance is not the average of red, green and blue. Each channel is first converted from its 0 to 255 value to a 0 to 1 value and then linearised to undo the sRGB gamma curve: values at or below 0.03928 are divided by 12.92, and higher values use ((v + 0.055) / 1.055) raised to the power 2.4. The three linear values are then weighted 0.2126 for red, 0.7152 for green and 0.0722 for blue, because the eye is far more sensitive to green light than to blue.
This tool applies exactly that formula to the two colours you pick and reports the ratio to two decimal places, with pass or fail badges for the normal-text thresholds.
Worked examples
Mid grey #767676 has a relative luminance of about 0.1812. Against white, whose luminance is 1, the ratio is 1.05 / 0.2312, which is 4.54:1. That is the lightest neutral grey that passes AA for body text on white; one step lighter, #777777, drops to 4.48:1 and fails.
White text on indigo #6366f1 comes out at 4.47:1. It looks readable to most people, but it falls just short of the 4.5:1 AA requirement for normal text. Darkening the background to #4f46e5, the tool's default, raises the ratio to 6.29:1, a comfortable AA pass that still misses AAA's 7:1. Pure red #ff0000 with white text is only 4.00:1, which surprises many designers.
Which threshold applies to what
The badges in the tool use the normal-text figures of 4.5 and 7. For large headings or icons, read the ratio itself and compare it with 3:1. Disabled controls and purely decorative text are exempt from the contrast requirement.
Accessibility law in many countries references WCAG 2.1 or 2.2 Level AA. The exact obligations vary by country and sector, so check the standard that applies to your organisation.
- Normal text, Level AA: at least 4.5:1.
- Large text, Level AA: at least 3:1. Large means at least 18 point (24 CSS px) regular, or 14 point (about 18.66 CSS px) bold.
- Normal text, Level AAA: at least 7:1.
- Large text, Level AAA: at least 4.5:1.
- User interface components and meaningful graphics such as icons, input borders and focus indicators (WCAG 2.1 criterion 1.4.11): at least 3:1 against adjacent colours.
Practical tips and known limits
Test the colours you actually ship, including hover, focus and disabled states, placeholder text and text over images. Text on a photo needs a scrim or overlay, because contrast varies across the image and a single ratio cannot describe it.
Enter colours as hex values such as #1d4ed8. Three-digit shorthand like #fff is expanded to #ffffff, and anything that is not a valid three- or six-digit hex code is flagged instead of being guessed at. Transparency is not supported; blend a semi-transparent colour onto its background first and test the resulting solid colour.
The WCAG 2 formula is known to overstate contrast for some dark colour pairs and understate it for some light ones. A newer method called APCA is being explored for future WCAG versions, but WCAG 2 ratios are what current audits and regulations use.
Color Palette & Contrast: frequently asked questions
What contrast ratio does AAA require?
At least 7:1 for normal text and 4.5:1 for large text. AAA is not usually required for a whole site, but it is a good target for long-form reading content.
Does WCAG contrast apply to buttons and icons?
Yes, since WCAG 2.1. Visual information needed to identify a control, such as a button border, an input outline or an icon with no text label, needs at least 3:1 contrast against the colours next to it.
Why does white text on bright red fail?
Pure red has a relative luminance of about 0.21, so white on #ff0000 is only 4.00:1. Darker reds such as #c00000 or below give enough contrast for body text.
Is a contrast ratio of 4.49 a pass?
No. The thresholds are minimums, and WCAG does not allow rounding up. A ratio must be at least 4.5:1 to pass AA for normal text.
What is the difference between hex and RGB colour codes?
They describe the same sRGB colour. Hex writes the red, green and blue values from 0 to 255 as two base-16 digits each, so #6366f1 is rgb(99, 102, 241). HSL describes the same colour as hue, saturation and lightness, here hsl(239, 84%, 67%). The tool shows hex, RGB and HSL for each colour.