Skip to main content

Crate wcag_contrast

Crate wcag_contrast 

Source
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§

ParseError
An error produced while parsing a hex color.
WcagLevel
The highest WCAG conformance level a contrast ratio meets 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) to 21.0 (black vs white). Order-independent.
level
Classify a contrast ratio into the highest WcagLevel it passes for normal or large_text (≥18pt, or ≥14pt bold).