WCAG 2.2 contrast math over hex colors.
The formula is the one from the spec: convert each sRGB channel to linear light, weigh them into relative luminance (0.2126 R + 0.7152 G + 0.0722 B), then ratio = (L1 + 0.05) / (L2 + 0.05), lighter over darker. The result lands between 1:1 (same color) and 21:1 (black on white).
Level AA asks for 4.5:1 for normal text and 3:1 for large text and UI components. Level AAA raises those to 7:1 and 4.5:1.
Summary
Functions
Checks a foreground/background pair against level AA.
Parses #rgb or #rrggbb into an {r, g, b} tuple of 0..255.
The contrast ratio between two hex colors, rounded to two decimals.
Accepts #rgb and #rrggbb, case insensitive.
Functions
Checks a foreground/background pair against level AA.
large: true relaxes the threshold to 3:1, for text at least 24px, or
18.66px bold (the WCAG definition of large scale).
Parses #rgb or #rrggbb into an {r, g, b} tuple of 0..255.
The contrast ratio between two hex colors, rounded to two decimals.
Accepts #rgb and #rrggbb, case insensitive.