Skip to content
Omnikalc

Color contrast calculator: does your text color pass WCAG?

Enter the RGB values of a text color and a background color to get the WCAG contrast ratio, the luminance of each color and whether it passes AA and AAA.

Updated on
Your inputs

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Results

Contrast ratio

5.74 :1

Passes AA
Luminance of the text color
0.1329
Luminance of the background color
1.0000
AA for normal text (4.5:1)
1
Pass
AA for large text and interface parts (3:1)
1
Pass
AAA for normal text (7:1)
0
Fail

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.

The screen size calculator relates a display’s size to its resolution and the golden ratio calculator is a classic tool for layout proportions.

Frequently asked questions

What is a good contrast ratio?

The Web Content Accessibility Guidelines ask for at least 4.5:1 for normal text and 3:1 for large text to reach level AA. The enhanced level AAA asks for 7:1 for normal text. As a rule, dark gray or black on white has a ratio above 7:1, and light gray on white often falls below 3:1.

How is the contrast ratio computed?

The relative luminance of each color is computed from its linear RGB values with weights of 0.2126, 0.7152 and 0.0722. The ratio then compares the lighter and the darker luminance, each with 0.05 added to account for the light that is always reflected by a screen. The formula is defined in WCAG 2.

Does the ratio work for every color?

The WCAG 2 formula is the legal standard in many countries, but it is known to be imperfect, particularly for dark mode and for some saturated colors. A newer method, APCA, is proposed for WCAG 3. Use the ratio as a check and test with real users when the design is critical.

What counts as large text?

WCAG defines large text as at least 18 point (24 pixels) or 14 point (about 18.7 pixels) if it is bold. Large text is easier to read and needs only 3:1 for AA. The same 3:1 applies to icons, chart lines and the borders of input fields that carry meaning.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.