stylelint-a11y
stylelint-a11y copied to clipboard
Call out statically detectable bad contrast
According to WCAG’s Success Criterion 1.4.3, text should have a contrast ratio of at least 4.5
, while large text (which starts at around 24px
or 18.67px
bold) should have a contrast ratio of at least 3
.
Although we cannot statically detect all cases of bad contrast (we cannot even predict what font size will be used, given browser zooming settings), we can detect the worst cases (ratio below 3
), and maybe additionally warn for values below a configurable threshold (say, 2.5
).
The formulas are here: https://w3c.github.io/wcag/understanding/contrast-minimum.html#dfn-contrast-ratio Here's the implementation in Chrome DevTools: https://source.chromium.org/chromium/chromium/src/+/master:third_party/devtools-frontend/src/front_end/common/ColorUtils.js;l=72-86;drc=91403e7b5c9ae2717db9243d177f8644d0d712be