Skip to content

wcagContrastRatio

wcagContrastRatio(fg, bg): number

Defined in: packages/math-color/src/encoding/rgb8/accessibility/wcag-contrast-ratio.ts:19

Computes the WCAG 2.x contrast ratio between a foreground and a background color. https://www.w3.org/TR/WCAG20/#contrast-ratiodef

The result is in the range [1, 21]. A value of 1 means no contrast (identical colors); 21 means maximum contrast (black on white or vice versa).

WCAG 2.x minimum thresholds: - AA normal text: 4.5 - AA large text / UI components: 3 - AAA normal text: 7 - AAA large text: 4.5

Rgb8

The foreground (text) color with components in the range [0, 255].

Rgb8

The background color with components in the range [0, 255].

number

The contrast ratio, a value in the range [1, 21].