Why contrast matters
Contrast is the difference in brightness between text and the colour behind it. Low contrast is hard for everyone to read in bright light or on a small screen, and it can make text unreadable for people with low vision or colour-vision differences. It is also one of the most common accessibility failures on the web, and one of the easiest to fix.
The Web Content Accessibility Guidelines (WCAG) define contrast as a ratio from 1:1 (no difference) to 21:1 (black on white), calculated from the relative luminance of the two colours.
The ratios you need
| Level | Normal text | Large text |
|---|---|---|
| AA (the usual target) | 4.5 : 1 | 3 : 1 |
| AAA (enhanced) | 7 : 1 | 4.5 : 1 |
Large text means about 18 point (24 pixels) regular, or 14 point (about 18.7 pixels) bold and above. Most laws and procurement rules that mention accessibility aim for AA.
Checking a pair of colours
The Color Contrast Checker takes a text colour and a background colour as hex codes, text first and then background, for example #111827 #ffffff. It returns both colours as RGB, the contrast ratio and pass or fail for AA and AAA at both text sizes. It accepts hex codes with three or six digits; colour names and rgb() values are not read.
Some results for text on a white background, calculated with the WCAG formula:
| Text colour | Ratio | Result |
|---|---|---|
| #94a3b8 (light slate) | 2.56 : 1 | Fails AA for all text |
| #777777 (grey) | 4.48 : 1 | Just misses AA for normal text; passes for large text |
| #767676 (slightly darker grey) | 4.54 : 1 | Passes AA |
| #4f46e5 (indigo) | 6.29 : 1 | Passes AA, not AAA |
| #595959 (dark grey) | 7.00 : 1 | Passes AAA |
| #111827 (near black) | 17.74 : 1 | Passes everything |
The near-miss between #777777 and #767676 shows why measuring beats eyeballing: the two look almost identical, yet one passes and one fails.
Fixing a failing pair
- Darken the text or lighten the background. Even a small step is often enough, as the grey example shows.
- Keep the brand colour, change where you use it. A brand colour that fails as text on white may pass as a button background with white text. Indigo #4f46e5 gives 6.29 : 1 either way round, because the ratio does not depend on which colour is text.
- Make the text bigger or bolder to move into the large-text threshold, if the design allows it.
- Do not rely on colour alone. Links, errors and chart series should also differ by underline, icon, pattern or label.
Remember hover, focus, disabled and placeholder states. Light grey placeholder text is a frequent failure.
Building a palette that passes
It is easier to design contrast in from the start than to repair it later. The Color Palette Generator builds complementary, analogous, triadic, tetradic and monochromatic sets from one seed colour, and a row of shades of that seed. It can copy hex codes and export CSS variables or a Tailwind config.
- Pick one strong accent and a few neutrals. Fewer colours look more consistent and are easier to test.
- Use the dark and light ends of the shade row for text and backgrounds, and the middle for accents.
- Run each text and background pair you plan to use through the contrast checker before you commit.
If you are matching colours to a photo or logo, the Image Color Extractor lists the eight most common colours in an image with hex codes, which you copy with a click. Check them for contrast before using them for text.
What a contrast ratio does not tell you
- It does not account for font weight, thin strokes, text over photographs or gradients. Test the worst part of the background.
- It does not tell you whether your colours work for every kind of colour-vision difference. Using the Image Filters grayscale option on a screenshot is a quick way to see whether your design still reads without colour.
- Passing the numbers is a minimum. Test with real users where you can, and on real screens in daylight.
A simple routine for design reviews
Make contrast checking part of every design review instead of a last-minute audit. List the text and background pairs in the design: body text, headings, links, buttons, form labels, placeholders, error messages and footers. Check each pair, record the ratio, and fix any that fail before the design goes to development.
Then check the states. A button that passes in its normal state can fail when hovered, focused or disabled. Keyboard focus outlines should also stand out from the background, so test them as well.
Keep the approved pairs in your style guide or CSS variables, so developers reuse colours that are already checked and nobody has to measure the same pair twice. When the brand colours change, re-run the list.