Skip to content

charton API


charton API / @chart-on/core / index / contrastRatio

Function: contrastRatio() ​

contrastRatio(foreground, background): number

Defined in: packages/core/src/util/color.ts:120

WCAG contrast ratio of foreground on background, from 1 to 21. A translucent foreground is blended over the background first; the background's own opacity is ignored, as nothing is known about what is under it. Throws, like parseColor, for a colour it cannot read; check with isColor first.

Parameters ​

foreground ​

string

background ​

string

Returns ​

number