SquishPixel Blog · Accessibility · Web design and UX · Front-end

Weighting contrast checks by character count shows 39.5 per cent of one site's text fails

According to DEV Community, an author audited all 38 pages of their site for accessibility and noticed that contrast tools count elements. A link with one word counts the same as a paragraph with hundreds. So they re-ran the check, weighting each colour pair by the number of characters it covers.

The method used Playwright, a browser automation tool, to visit the 38 URLs in the sitemap and walk every text node. For each one, the script found the real background by climbing the page structure to the first ancestor with a mostly opaque background. The site has ten different backgrounds, and 197,293 characters sit on #0a0a0a.

The result was that 39.5 per cent of characters fail. Two greys, #737373 and #525252, account for 76,098 of the 84,508 failing characters. The ranking flipped against the earlier element-based audit. #525252 had the most failing elements, 1,307, but at about 18.9 characters each it is mostly short labels and footer links, so it falls to third by characters.

#737373 covers 510 elements at about 107.6 characters each, which is paragraph text. It is set at 13 and 14 pixels, so it needs a 4.5:1 ratio under WCAG, the web accessibility guidelines, and it reaches 4.18:1. The author says moving it to #797979 cuts failures from 39.5 to 13.9 per cent. Because some text sits on #111111 cards, #7c7c7c works everywhere. The author suggests most #525252 text should move to the same replacement, while purely decorative greys used for borders can stay.

The author lists limits. Text opacity was not factored in, so faded text may look better in the results than it does on screen. Gradients or images behind text were not checked, though the site has none behind prose. Characters are also an imperfect proxy for reading, since they over-weight long URLs and under-weight short headings.

Why it matters

Element counts can point you at the wrong fix. A tool may rank a colour first because it appears on many small labels, while another colour quietly covers most of the actual reading on your pages. Weighting by text volume shows where readers spend their time.

The case also shows that a contrast failure can be small. Here, a change of a few hex values on body text made a large difference. That makes it a cheap job, especially for sites with hand-typed colours that can be found and replaced.

Treat the numbers as one site's results, not a general rule. The author is clear that the method has gaps.

Source: DEV Community. This brief summarises their reporting; read the original for the full detail.