Skip to the content.

Color contrast

Check

python3 scripts/contrast.py "#767676" "#ffffff"              # ratio + pass/fail table
python3 scripts/contrast.py "#9ca3af" "#ffffff" --fix         # suggest nearest passing foreground
python3 scripts/contrast.py "rgb(59 130 246)" "#0b1220" --level AAA --large

Accepts #rgb, #rrggbb, #rrggbbaa (alpha is composited over the background), rgb()/rgba() with commas or spaces, and CSS named colors for the common basics (white, black, red…). The ratio uses the WCAG 2.x relative luminance formula.

Thresholds (WCAG 2.2)

What AA AAA
Normal text 4.5:1 (SC 1.4.3) 7:1 (SC 1.4.6)
Large text: at least 24 CSS px regular, or 18.66 CSS px (14pt) bold 3:1 4.5:1
UI component boundaries, icons that convey meaning, focus indicators, chart parts needed to understand them 3:1 (SC 1.4.11) -

Exceptions: disabled controls, purely decorative elements, logos.

Workflow

  1. List every foreground/background pair actually used: body text, muted/secondary text, links (against surrounding text too if they are only distinguished by color), placeholder text, buttons in all states (default, hover, focus, disabled), focus rings, form borders, error/success text, text on images or gradients (test the worst spot).
  2. Check light and dark themes separately.
  3. For failures, use --fix to find the nearest passing shade in the same hue, and update the design token rather than the one-off usage.
  4. Remember the WCAG 2 formula has known blind spots (it can overrate some dark-on-dark pairs and underrate some light-on-dark ones). Passing is required for conformance; also eyeball the result. APCA is a newer perceptual model discussed for future guidelines, but WCAG 2.x ratios are what conformance is measured against today.