Color Contrast and Accessibility: A Practical Guide for Designers and Developers
By the Hex Color Picker Team. Published . 9 minute read.
Color contrast is the difference in brightness between text (or another element) and the background behind it. The Web Content Accessibility Guidelines, usually called WCAG, measure it as a ratio from 1:1 (no difference) to 21:1 (black on white). To meet level AA, normal text needs at least 4.5:1, and large text and interface components such as button borders need at least 3:1.
That sounds abstract, but the practical effect is simple: if text doesn't have enough contrast, many people can't read it, especially in bright light, on a dim screen, or with low vision. This guide explains how the ratio is calculated, what the thresholds are, and how to check and fix real colors. Every number below was calculated with the same code that powers the tools on this site.
Why contrast matters
Low contrast affects more people than the ones who think of themselves as having a visual impairment. Glare on a phone outdoors, a cheap laptop screen, tired eyes, age-related changes in vision and a projector in a lit room all reduce the effective contrast of what you design. Text that reads fine on your calibrated monitor can vanish in those conditions.
Contrast is also one of the easiest accessibility problems to prevent. Unlike many accessibility issues, it can be measured with a single number, and fixing it usually means nudging one color a little.
It is also a legal and procurement matter in many places, since WCAG is the standard that most accessibility rules refer to. WCAG 2.2 is the current published version. A newer contrast model has been proposed for a future WCAG 3, but it is not part of the requirements today, so the WCAG 2 formula described here remains the one that matters.
How the contrast ratio is calculated
The ratio compares the relative luminance of two colors. Luminance is a measure of how bright a color is to the eye, from 0 (black) to 1 (white). It takes four steps:
- Scale each channel to 0 to 1. Divide red, green and blue by 255.
- Linearize each channel. Screens apply a curve to the numbers, so this step undoes it. If the value is 0.03928 or below, divide it by 12.92. Otherwise, add 0.055, divide by 1.055 and raise the result to the power 2.4.
- Combine the channels. Luminance L = 0.2126 x R + 0.7152 x G + 0.0722 x B. The weights reflect that the eye is most sensitive to green and least sensitive to blue.
- Compare the two luminances. The ratio is (L1 + 0.05) / (L2 + 0.05), where L1 is the lighter color.
Here it is worked through for a mid grey, #767676, on white:
- The channel value is 118, so scaled it is 118 / 255 = 0.4627.
- Linearized: (0.4627 + 0.055) / 1.055 = 0.4907, and 0.4907 to the power 2.4 is 0.1812.
- Because all three channels are equal, the luminance is also 0.1812.
- White has a luminance of 1. The ratio is (1 + 0.05) / (0.1812 + 0.05) = 4.54.
So #767676 on white is 4.54:1, which just passes the 4.5:1 threshold for normal text. It is a famous value for exactly that reason: it is the lightest grey that passes on white.
The weights tell you why HSL lightness is not a reliable guide to contrast. The same HSL lightness can have very different luminance, because green contributes so much more than blue. Yellow, #FFFF00, has a luminance of 0.928, while blue, #0000FF, has only 0.072.
The thresholds
WCAG sets different minimums for different kinds of content:
| Content | Level AA | Level AAA |
|---|---|---|
| Normal text | 4.5:1 | 7:1 |
| Large text | 3:1 | 4.5:1 |
| Interface components and graphics (borders, icons, focus rings) | 3:1 | no separate requirement |
"Large text" means text of at least 18 point (24 pixels), or at least 14 point (about 18.66 pixels) when bold. Most websites aim for AA. AAA is stricter, and WCAG itself notes that it isn't always achievable for every page, but it is a useful target for body text where you can manage it.
Some content is exempt: purely decorative elements, inactive (disabled) controls, and logos. Even so, it is good practice to keep disabled states readable enough that people can tell what they say.
Worked examples
These are real pairs, calculated with the site's conversion code.
| Text color | Background | Ratio | Passes AA for body text? |
|---|---|---|---|
#767676 | White | 4.54:1 | Yes, barely |
#777777 | White | 4.48:1 | No, by a hair |
#595959 | White | 7.00:1 | Yes, and AAA |
#1E90FF (dodgerblue) | White | 3.24:1 | No, but fine for large text |
#0066CC | White | 5.57:1 | Yes |
#008080 (teal) | White | 4.77:1 | Yes |
#FFA500 (orange) | White | 1.97:1 | No |
| White | #BF2163 | 5.81:1 | Yes |
#9CA3AF (a common light grey) | White | 2.54:1 | No |
#6B7280 (a common mid grey) | White | 4.83:1 | Yes |
#000080 (navy) | #E6E6FA (lavender) | 13.01:1 | Yes, and AAA |
Look at the first two rows. #767676 and #777777 are indistinguishable by eye, but one passes and the other fails. This is why you measure rather than judge by looking.
The dodgerblue row is the one that surprises people. It is a good-looking bright blue, but on white it is only 3.24:1. That's enough for a large heading or a button border, but not for paragraph text or small links. The same color works well the other way around: white text on dodgerblue is also 3.24:1, but black text on it is 6.49:1.
When you want a bright blue that is also readable as text, move toward a darker blue. #0066CC looks like a close cousin of dodgerblue and passes at 5.57:1.
Fixing a failing pair
When a combination falls short, you have three levers, and the easiest is usually the lightness of one color:
- Darken the text, or lighten the background. Lower the lightness of a text color in HSL until the ratio passes, then stop. Keep the hue and saturation, so it still looks like the same color. The HSL color picker makes it easy to lower lightness in small steps, and you then re-check the ratio after each step.
- Swap which color carries the text. Dodgerblue fails with white text but passes with black text, so reverse them.
- Change the text size or weight. If the design really needs the lighter color, make the text large, so the 3:1 threshold applies.
Don't use opacity to soften text. A dark grey set to 60% opacity over a colored background has a contrast you can't read off the color code, so you have to measure the actual blended result.
Beyond text
Contrast applies to more than words.
- Interface components. Form field borders, icons that carry meaning, checkboxes and focus outlines should have at least 3:1 against what is around them. A pale grey border on a white input is a very common failure.
- Focus indicators. Keyboard users rely on the outline to know where they are. A focus ring should be easy to see against both the element and the page.
- Charts and graphs. Adjacent bars, lines or slices should be distinguishable. If color is the only difference, add labels, patterns or direct annotations.
- Links inside text. If a link is only distinguished from the surrounding text by color, the colors need to differ from each other by at least 3:1 as well as pass against the background. The simplest fix is to underline links.
Don't rely on color alone
A separate WCAG rule says that color must not be the only way to convey information. A form field that only turns red when it has an error, or a chart where categories differ only in hue, fails people who can't tell those colors apart. Some color vision deficiencies make red and green hard to distinguish, and others affect blues and yellows.
The remedy is easy: add a second cue. An error message in words, an icon, a pattern in the chart or a bold label all work. This matters for the colors you choose, too. If red means error and green means success in your interface, don't depend on the difference between them alone.
Contrast in dark mode and on images
Dark mode flips the problem but doesn't remove it. Pure white text on pure black can feel harsh and cause halos for some readers, so many designers choose an off-white on a very dark navy or grey. This site's dark theme uses #ECEEFB text on #0D0F21, a ratio of 16.43:1, which is high without the glare of full white on black. In light mode, its text is #141735 on #EEF1F7, at 15.42:1, with secondary text at 6.32:1. The main text in both modes exceeds the 7:1 AAA threshold.
Text over photos and gradients is harder, because the background changes from one place to the next. Test the lightest and darkest parts of the area behind the text, and place a solid or semi-opaque panel behind the text if the image can't guarantee the ratio. The gradient guide covers the same issue for gradients.
A testing routine that works
You don't need an expensive audit to catch the common problems. This takes a few minutes:
- List your color pairs. Body text on background, secondary text on background, links, buttons (text on fill), borders, placeholder text and focus rings.
- Calculate the ratio for each pair. Convert each color to hex, then use any WCAG contrast checker. You can also read your color's ratio against white and black on each named color page, for example teal.
- Mark the failures and fix them. Use the three levers above.
- Test the states. Hover, focus, active and disabled states are often missed.
- Look at it in bad conditions. Turn the screen brightness down, view it outside, or zoom the page to 200%.
- Retest after changes. One tweak to a brand color can break many pairs at once, which is why storing colors in CSS variables and checking the whole set together is worth doing. See how to build a color palette for a website.
Common mistakes
- Light grey placeholder text. It is often the first thing to fail, at 2.5:1 or below.
- Judging by eye on one screen. Your display may be much better than your users'.
- Thin, light text. Thin fonts have less pixel coverage, so they look lower in contrast than the ratio suggests. Be more generous with them.
- Brand colors used as text colors without checking. Many bright brand colors, like dodgerblue and orange, only work as backgrounds or large accents.
- Forgetting hover and focus. A button that passes at rest can fail in its hover state if the color shifts toward the background.
- Testing only light mode. Check dark mode separately.
Frequently asked questions
What is the minimum contrast ratio for text?
4.5:1 for normal text at level AA, and 3:1 for large text. Level AAA asks for 7:1 and 4.5:1.
What counts as large text?
At least 18 point (24 pixels) in regular weight, or at least 14 point (about 18.66 pixels) in bold.
Is black on white the best choice?
It has the highest possible ratio, 21:1, but extremes aren't required. A very dark navy or grey on a slightly off-white background is easier to read for many people and still has very high contrast.
Does contrast apply to logos?
Logos and purely decorative elements are exempt from the contrast requirements.
How do I check a color pair quickly?
Convert both colors to hex, then enter them into a WCAG contrast checker. The hex color picker gives you the exact hex code for each color to enter into a checker, and each named color page lists the ratio for white and black text on it.
Do I need to meet AAA?
Most sites target AA. AAA is worth aiming for on long-form body text where you can do it without hurting the design, but WCAG does not require it for whole sites.
Where can I read the standard?
The WCAG 2.2 specification is published by the W3C at www.w3.org/TR/WCAG22.