Skip to content

Function: contrast()

ts
function contrast(color1, color2): string;

Defined in: contrast.ts:17

The contrast function calculates the contrast ratio between two colors. Implementation of http://www.w3.org/TR/WCAG20/#contrast-ratiodef

Parameters

ParameterTypeDescription
color1ColorThe first color to compare.
color2ColorThe second color to compare.

Returns

string

  • The contrast ratio between two colors in the format of "X.X:1".

Throws

  • Throws an error if either of the color arguments is invalid.