Contrast Fixer: Nearest Accessible Color
Find the closest color that reaches WCAG 3:1, 4.5:1 or 7:1 contrast — and repair a palette.
How it works
Enter a text and a background color. If the pair fails the WCAG contrast target, get the nearest darker and lighter versions of the color you want to change (same OKLCH hue, measured by CIEDE2000). Optionally check a whole palette: every background gets its readable text colors and a repaired one where none passes.
- Contrast is the WCAG 2.x ratio (L1 + 0.05)/(L2 + 0.05) of relative luminances from 8-bit sRGB. Thresholds compare unrounded ratios; every suggestion is checked again on its rounded HEX value.
- Only the chosen color changes. Its OKLCH hue and chroma are kept and its lightness is moved towards black (darker) and towards white (lighter) by bisection until the target is just reached; chroma is reduced by the CSS Color 4 gamut mapping if the color would leave sRGB.
- The suggestion is the option with the smaller CIEDE2000 difference to the original. Black or white is offered only when neither direction can reach the target.
- Palette check: for each color as background, the other palette colors that pass are listed (best ratio first). If none passes, the palette color with the highest ratio is adjusted as above. APCA is not used.
Sources
- WCAG 2.2: Contrast (Minimum), relative luminance and contrast ratio (W3C)
- CSS Color Module Level 4 — §12 Interpolation, §13 Gamut mapping (W3C)
- Sharma, Wu and Dalal (2005): The CIEDE2000 color-difference formula (University of Rochester)
- Björn Ottosson (2020): A perceptual color space for image processing (Oklab) (Björn Ottosson)
Part of Lumina
-
Lumina Photo editor & image toolkit
Bring out what you saw. A free photo studio, right in your browser.
Related tools
- Palette Contrast Matrix – Check every palette color pairing against WCAG text contrast thresholds.
- Photo Palette & Text Contrast – Check palette luminance and choose readable text for photos and graphics.
- Color Blindness Palette Simulator – Simulate protan, deutan and tritan vision for a palette and find colors that become confusable.
- Perceptual Gradient Generator (OKLCH, OKLab, CSS) – Build smooth multi-stop CSS gradients in OKLab or OKLCH, with a fallback for every browser.
How to use the Contrast Fixer
Find the closest colour that reaches WCAG 3:1, 4.5:1 or 7:1 contrast, keep its hue, and repair a whole palette pair by pair.
What it is for
A contrast checker tells you that sea green on cream fails. It does not tell you which sea green would pass. Designers then nudge the colour by hand, check again and repeat — and often drift far from the original shade.
The Contrast Fixer does that search for you. You give it a text colour, a background colour and a target from WCAG 2.x (3:1 for large text and interface parts, 4.5:1 for body text, 7:1 for the AAA level), and choose which of the two may change. It keeps that colour's hue and saturation, moves only its lightness darker and lighter just far enough to reach the target, and recommends the option that changes the colour least, measured with CIEDE2000.
You can also paste a whole palette of 2–24 colours. For every colour used as a background, the tool lists the palette colours that are already readable on it and repairs the backgrounds where none passes.
It uses the WCAG 2.x formula only. It does not judge text over photos, transparency or font weight.
Worked example
The first example puts sea green #72A5A0 text on cream #ECF0DE with the 4.5:1 target. The pair only reaches 2.38:1. The result:
Use #437570 instead of #72A5A0: 4.5:1, a change of ΔE2000 17.5.
Only a darker option exists, because no lighter version of that green can stand out from a cream background. #437570 is still clearly the same sea green, just deeper.
The second example is the classic grey question: #777777 on white reaches 4.48:1, just short of AA. Asking for 7:1 suggests #595959 — the well-known AAA grey — at a change of 11.38.
The third example keeps white text and lets the background #E07A5F (coral, 2.95:1) change: #BC5940 reaches 4.52:1 with a change of 11.5. Its palette check of #3D405B #E07A5F #F2CC8F #81B29A finds only 2 of 12 pairs readable. On the green #81B29A, the navy #3D405B only needs a tiny step to #393B56 (4.53:1, change 1.66).
How to read the result
- Before and after shows both pairs as a swatch with their ratios.
- Contrast now, Target and Suggested color are the headline numbers. Change (ΔE2000) says how far the suggestion is from your colour: under about 2 is hard to notice, 10–20 is a clear but related shade.
- Options lists the darker and lighter candidates that reach the target; the first is the suggestion.
- The palette table shows, per background, the readable palette colours, the best text colour and where it comes from: palette, adjusted (a palette colour moved in lightness) or black/white.
Tips and common mistakes
- Decide what may move. Brand backgrounds usually stay; then adjust the text colour. For buttons it is often the background.
- Ratios are rounded for display, but every suggestion is tested on its exact HEX value, so 4.5 really passes.
- 3:1 is only for large text (about 24 px, or 19 px bold) and for icons and borders, not for body text.
- If the change is very large, the colour cannot work in that pair. Pick another palette colour instead.
- Check the result for colour vision too, for example with the CVD simulator.
FAQ
Why only darker or lighter, not a different hue?
Hue carries the meaning of a brand or a status colour. Keeping it and changing only lightness gives the most recognisable fix.
Does it use APCA?
No. The tool follows WCAG 2.x contrast, which is what current accessibility rules refer to.
What if no colour reaches the target?
Then black or white is offered. If even they fail — for example 21:1 against grey — the tool tells you to lower the target.
Which colour formats can I enter?
Any CSS colour: HEX, names, rgb(), hsl(), oklch(), lab() and more. Colours outside sRGB are mapped into it first.
Guide last updated:
For scripts and AI agents
- JSON API:
POST https://luminacontrastfixer.usefulweb.app/api/v1/calculate(same calculation as this page) - Interface description: OpenAPI 3.1 · AI guide: llms.txt
- MCP server (Streamable HTTP):
https://luminacontrastfixer.usefulweb.app/mcp· tool namelumina_contrast_fixer
Example request
curl -s -X POST https://luminacontrastfixer.usefulweb.app/api/v1/calculate \
-H 'content-type: application/json' \
-d '{"foreground":"#72A5A0","background":"#ECF0DE","target":"4.5","adjust":"foreground","palette":""}'