Skip to content

colorContrast

Based on the color provided, this function will return a “white” or “black” color that is suitable for text placed on top of that provided color. The choice maximizes the WCAG 2.x contrast ratio against the background, so the more legible of the two text tokens always wins.

For each background swatch, the higher-contrast of the two text tokens is returned — the dark token over the pale #f8f9fa and #ffeb3b fills, the light token over the darker ones.

import {colorContrast} from "@d3plus/color";

colorContrast("#b22200");
colorContrast("#f8f9fa");
colorContrast("#1f77b4");
colorContrast("#ffeb3b");
colorContrast("#2c3e50");
colorContrast("#9ed763");

Parameters

import {colorContrast} from "@d3plus/color";
crequiredstring

A valid CSS color string.

uPartialDefault {}

An object containing overrides of the default colors.