Kaizen
Browse modulesQR codeqr-code/sharedFunctions

Function: getContrastRatio()

function getContrastRatio(foreground: string, background: string): number | null;

Defined in: shared/qr-code/contrast.ts:137

WCAG 2.1 contrast ratio between two colours, in the range 1–21.

Returns null when either colour can't be resolved statically (a CSS custom property, currentColor, an unsupported syntax) — the caller must treat that as "unknown", not as "fine".

Also null when either paint is translucent: the real ratio then depends on whatever is composited behind it, and returning a number computed from the straight channels would be confidently wrong.

Parameters

ParameterType
foregroundstring
backgroundstring

Returns

number | null

On this page