Quick answer
Enter the background colour in a contrast checker, compare the ratio for black text with the ratio for white text, and use the higher one. Then check that ratio against the WCAG 2.2 thresholds for the size of your text:
- Normal text, Level AA: at least 4.5:1.
- Large text, Level AA: at least 3:1.
- Normal text, Level AAA: at least 7:1.
- Large text, Level AAA: at least 4.5:1.
In FreeToolsKit's Color Picker & HEX/RGB/HSL Converter, type the colour into HEX, then read the Text contrast (WCAG) panel. It shows a ratio for Black text and one for White text, each with a Pass or Fail for those four thresholds.
This answers one question: should text on this colour be black or white? It compares your colour with pure black and pure white only. It can't test two colours you choose, such as grey text on a blue button, and it can't measure text over a photo or a gradient. A semi-transparent colour is checked only as it would look over a white or a black page.
What the thresholds mean
WCAG 2.2, the current W3C Recommendation, sets these minimums in success criteria 1.4.3 (Level AA) and 1.4.6 (Level AAA) (W3C: Understanding SC 1.4.3, W3C: Understanding SC 1.4.6).
- Large text means at least 18 point, or 14 point bold (WCAG 2.2: large scale). In CSS, 14pt and 18pt are "approximately 18.5px and 24px" (W3C, SC 1.4.3 above).
- Don't round up. The computed ratio "should not be rounded (e.g., 4.499:1 would not meet the 4.5:1 threshold)" (W3C, SC 1.4.3 above).
- Logos are exempt. "Text that is part of a logo or brand name has no contrast requirement" (W3C, SC 1.4.3 above). Headings, buttons and body text in brand colours are not.
The ratio runs from 1:1 to 21:1. It is (L1 + 0.05) / (L2 + 0.05), where L1 and L2 are the relative luminance of the lighter and darker colour (WCAG 2.2: contrast ratio). Relative luminance weights the linearised red, green and blue channels 0.2126, 0.7152 and 0.0722 (WCAG 2.2: relative luminance). The tool's code uses that formula.
Check a colour in the tool
- Enter the colour. Type it into HEX (for example
#1F66D1), paste it into Paste a CSS color, use Choose a color, or pick it from an image under Pick from image. - If the colour is semi-transparent, choose what's behind it under The color is transparent — page background behind it: White or Black. The panel then names the blended colour it is testing.
- In Text contrast (WCAG), read the two ratios, such as "White text: 5.41:1", and the four lines under each, such as "AA normal text (4.5:1): Pass".
- Use the text colour that passes the level you need for your text size.
The ratios are shown cut off at two decimals, never rounded up. Pass or Fail uses the exact value.
The test: three brand colours and one transparent colour
We tested three fictional brand colours and one semi-transparent version, typed into HEX and Opacity (%) on the tool page in Chromium. The results, as displayed:
- Mid blue
#1F66D1: "White text: 5.41:1" passes AA normal, AA large and AAA large, and fails AAA normal. "Black text: 3.87:1" passes AA large only. Use white; it is fine for body text at Level AA. - Bright yellow
#FFC72C: "Black text: 13.45:1" passes all four. "White text: 1.56:1" fails all four. Use black. - Mid grey
#777777: "Black text: 4.68:1" passes AA normal, AA large and AAA large. "White text: 4.47:1" fails AA normal and passes AA large only. Use black for body text. White is acceptable only for large text. - Mid blue at 60% opacity (
#1F66D199): over a White page it blends to#79A3E3, and black text passes all four at 8.16:1, while white text fails all four at 2.57:1. Over a Black page it blends to#133D7D, and the answer flips: white text passes all four at 10.54:1, and black text fails all four at 1.99:1.
The grey shows why rounding matters. White on #777777 is 4.478:1 when calculated in full. Rounded to one decimal that reads 4.5, which looks like a pass, but it fails. WebAIM gives the same example: #777777 "with a 4.47:1 contrast ratio—does not meet this requirement" (WebAIM: Contrast and Color Accessibility).
The transparent blue shows why the page behind a colour matters. The same colour code needs white text on a dark page and black text on a light one.
Checked against the formula. We recalculated every ratio from the WCAG definitions with our own script, blending the transparent colour first. Each displayed ratio matched our figure cut off at two decimals, and every Pass and Fail matched.
Picking from an image. We also uploaded a 320 × 80 pixel PNG with the four colours as flat squares and clicked each one. The opaque squares gave exactly #1F66D1, #FFC72C and #777777, with the same ratios as above. The semi-transparent square came back as #2066D099, one step off in red and blue. Its blended colours and ratios were unchanged, but if you need an exact code, type it from your brand guidelines rather than picking a transparent pixel.
These are four test colours, not a survey. Your colours will give their own numbers.
Why black or white always passes AA
By our calculation from the WCAG formula, at least one of black or white text reaches 4.58:1 on any opaque colour. The two ratios are equal at a relative luminance of about 0.179, where both are about 4.58:1. Any lighter colour gives black text more than that, and any darker colour gives white text more. A brute-force check of all 16,777,216 8-bit sRGB colours found no exception.
So for normal-size text, one of the two always passes Level AA. The real decisions are these:
- Is the margin comfortable? Near the crossover, as with
#777777, the winner passes AA by a small margin and the other colour fails. - Do you need AAA? On mid-tones neither may reach 7:1. By the same calculation, that is true for about 39% of 8-bit sRGB colours.
- Will you use black or white at all? If your design uses a dark grey or a second brand colour for text, this check doesn't cover it.
What this check can't tell you
- Two colours you choose. For grey text on a blue button, or a coloured link on a tinted panel, use a checker that takes both colours. WebAIM's Contrast Checker takes a foreground and a background colour, with an optional alpha value for the foreground.
- Text over photos and gradients. That text still needs enough contrast, "but WCAG does not provide any guidance on how to measure their contrast"; WebAIM recommends "testing the area where contrast is lowest" (WebAIM: Contrast and Color Accessibility). W3C's failure technique F83 starts with the part of the image that is "lightest (for light text)" or "darkest (for dark text)" (W3C: F83). You can use Pick from image on a screenshot to sample that area and read the ratio, allowing for small colour shifts in screenshots. A single picked pixel is only a quick check: if it fails, look at the background behind each letter, as F83 does.
- Transparency over other backgrounds. Lowering opacity lets the colour underneath "bleed through" and changes the contrast (WebAIM, above). The tool blends only over white or black. Over a cream, coloured or photo background, sample the colour as it actually appears on screen.
- Whether colour is the only cue. A good ratio doesn't make red and green states easy to tell apart for people with colour vision deficiency. WCAG's success criterion 1.4.1 says "Color is not used as the only visual means of conveying information" (W3C: Understanding SC 1.4.1). Add text, an icon or an underline.
- Whether the text is readable. Thin or small type can still be hard to read at a passing ratio. The CSS Color 5 draft notes that a pair with enough contrast "does not guarantee that the text will be legible" (W3C: CSS Color Module Level 5).
About APCA and WCAG 3. APCA is an alternative contrast method. Its author argues that WCAG 2 "far overstates contrast for dark colors" (APCA: Why APCA as a New Contrast Method?), but it isn't a W3C standard. WCAG 3 is still a Working Draft, and it says "The contrast algorithm used in WCAG 3 is yet to be determined" (W3C: WCAG 3.0 Working Draft). The 4.5:1, 3:1 and 7:1 ratios of WCAG 2.2 are the ones to meet today.
Before you use the colour
- Text size: you know whether the text is normal or large (18pt, or 14pt bold), and which level you need, AA or AAA.
- Winner: the text colour you chose passes that threshold, read from the exact Pass or Fail, not a rounded ratio.
- Transparency: for a semi-transparent colour, you checked it over the background it will really sit on.
- Other pairs: any text that isn't pure black or white, and any text over an image or gradient, has its own check.
- Second cue: anything that signals meaning with colour also has a label, icon or underline.

