After you invert an image, how do you tell whether anything is still readable?
Inverting an image is one click. Deciding whether the result is usable takes a different question, and it is not "does it look inverted". It is "did the contrast between the things that must be told apart survive the fli
Inverting an image is one click. Deciding whether the result is usable takes a different question, and it is not "does it look inverted". It is "did the contrast between the things that must be told apart survive the flip".
What inversion actually changes
Inversion works per channel: each red, green and blue value v becomes 255 − v. Light areas turn dark, dark areas turn light, and hue relationships are preserved in a rough sense while lightness relations flip.
The trap is assuming that this flips the thing that matters. Readability depends on relative luminance, a single number derived from the three channels after a linearisation step, not on the raw channel values. Two colours can have the same channel values inverted and end up nowhere near a mirrored luminance. So the useful frame is: inversion moves pixels, and luminance is what you then have to re-check.
The thresholds the check is measured against
WCAG 2.2 sets the numbers. Success criterion 1.4.3 Contrast (Minimum) requires that "the visual presentation of text and images of text has a contrast ratio of at least 4.5:1", with an exception: "Large-scale text and images of large-scale text have a contrast ratio of at least 3:1".
Non-text elements have their own criterion, 1.4.11, at 3:1, which covers things like icon strokes, chart lines, form borders and focus indicators.
The ratio itself is defined in the glossary: "(L1 + 0.05) / (L2 + 0.05), where L1 is the relative luminance of the lighter of the colors, and L2 is the relative luminance of the darker of the colors", with the note that "Contrast ratios can range from 1 to 21".
Three numbers, then: 4.5, 3, and a formula bounded by 21. Everything below is an application of those.
What happens to the ratio when both sides invert
Here is where intuition fails. Inverting text and background together does not preserve contrast. It moves both luminances, and the formula is not symmetric around a flip.
Worked with relative luminance values directly, using the WCAG formula:
A pair at 0.6 and 0.1 gives (0.65)/(0.15), about 4.33, which misses 4.5. Inverted to 0.4 and 0.9, it becomes (0.95)/(0.45), about 2.11. The pair got worse.
A pair at 0.9 and 0.5 gives about 1.73. Inverted to 0.1 and 0.5, it gives about 3.67. Better, still short of 4.5.
A pair at 1.0 and 0.2 gives 4.20. Inverted to 0 and 0.8, it gives 17.0. Much better.
A pair at 0.7 and 0.3 gives 2.14, and after inversion 0.3 and 0.7 gives 2.14 again. Unchanged, because the two values sum to 1.
One caveat belongs in front of that table. Those figures substitute relative luminance directly, which shows the direction of the effect. A real image will not land exactly on 1 − L, because sRGB values carry a transfer function: inverting the channel bytes is not the same operation as inverting linear luminance. The direction of the change holds, the exact numbers do not, and the number you rely on should come from a measurement rather than from this arithmetic.
The practical reading is simple. Inversion can improve contrast, damage it, or leave it alone. It is not a fix, and it cannot be assumed in either direction.
What inversion cannot fix
Colour-only distinctions survive inversion as a problem. WCAG 1.4.1 Use of Color asks that colour is not "used as the only visual means of conveying information, indicating an action, prompting a response, or distinguishing a visual element". A red and a green status dot that differ mainly in hue will still differ mainly in hue after inversion, and a reader who cannot separate them will not be helped.
Photographic detail is another limit. Inversion changes tones, not resolution, focus or compression artifacts. A soft screenshot stays soft.
Small features are the third. A one-pixel border, a thin icon stroke or a low-contrast focus ring is measured against the 3:1 threshold for non-text content, and inverting a pair that already sat below it can easily push it further down, as the 0.6/0.1 case shows.
A short checklist
Four steps, in order.
List the pairs that carry meaning: body text on its background, headings, button labels, icon strokes, borders, chart series.
For each pair, get the luminance values and compute the ratio with the WCAG formula, or measure them with a checker that does.
Compare against 4.5 for body text, 3 for large text, 3 for non-text.
Only then decide whether to keep the inverted version. If a pair that matters drops, keep the original and invert a copy for the parts that need it.
An inversion tool that shows the before and after side by side makes the first step faster, because you can see which pairs to measure instead of guessing: https://colorinvert.com/color-inverter
The habit worth building is small: treat inversion as a change to be verified, not a state to be applied. The numbers above are thresholds, not opinions, and they are the same before and after the flip.
Sources
- WCAG 2.2, Success Criterion 1.4.3 Contrast (Minimum): https://www.w3.org/TR/WCAG22/#contrast-minimum
- WCAG 2.2, contrast ratio definition: https://www.w3.org/TR/WCAG22/#dfn-contrast-ratio
- WCAG 2.2, Success Criterion 1.4.11 Non-text Contrast: https://www.w3.org/TR/WCAG22/#non-text-contrast
- WCAG 2.2, Success Criterion 1.4.1 Use of Color: https://www.w3.org/TR/WCAG22/#use-of-color
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.