Skip to main content

Function: getContrastRatio()

getContrastRatio(color1, color2): number

Calculates the contrast ratio between two colors according to WCAG 2.0.

The contrast ratio is defined as (L1 + 0.05) / (L2 + 0.05), where L1 is the relative luminance of the lighter of the two colors, and L2 is the relative luminance of the darker of the two colors.

Parameters

ParameterTypeDescription
color1ColorThe first color.
color2ColorThe second color.

Returns

number

A number representing the contrast ratio. The ratio can range from 1 to 21.

Defined in

accessability/components/contrast-ratio.ts:15