Expand description
§wcag-contrast — color contrast for accessibility
Compute WCAG 2 color contrast ratios from hex or RGB colors and check whether they pass AA / AAA for normal or large text. A small, focused, zero-dependency accessibility helper for linters, design tools, and CI checks.
use wcag_contrast::{contrast_hex, level, WcagLevel};
let ratio = contrast_hex("#ffffff", "#000000").unwrap();
assert_eq!(ratio, 21.0); // maximum possible contrast
assert_eq!(level(ratio, false), WcagLevel::AAA);Structs§
- Rgb
- An 8-bit-per-channel sRGB color.
Enums§
- Parse
Error - An error produced while parsing a hex color.
- Wcag
Level - The highest WCAG conformance level a contrast
ratiomeets for the given text size.
Functions§
- contrast_
hex - Parse two hex colors and return their contrast ratio.
- contrast_
ratio - The WCAG 2 contrast ratio between two colors, from
1.0(identical) to21.0(black vs white). Order-independent. - level
- Classify a contrast
ratiointo the highestWcagLevelit passes for normal orlarge_text(≥18pt, or ≥14pt bold).