Skip to main content

contrastRatio

WCAG contrast ratio, from 1 to 21, between two opaque colours.

This is a function exported by @mapcairn/theme, checked against version 0.2.0.

Signature​

import { contrastRatio } from "@mapcairn/theme";

function contrastRatio(a: ColourInput, b: ColourInput): number;

Parameters​

  • a (ColourInput)
  • b (ColourInput)

Returns​

number

Throws​

  • When either colour is translucent. Composite it over a backdrop with compositeOver first, because the ratio depends on it.

See also​

Source: packages/theme/src/contrast.ts:356