getForeground

Commons
stable

Returns "#fff" or "#000" depending on which foreground color produces the best APCA contrast against the given background. Prefers white when both reach the 50 Lc threshold.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

color
required
TColorType
The background color in any format accepted by parseColor (#hex, rgb(), hsl(), RGBA/HSLA object, or number).

API

Return value

The value returned by this util.

"#fff" when white text yields sufficient APCA contrast (Lc ≥ 50) or beats black contrast; "#000" otherwise.

Usage

Examples

Ready-to-paste usage snippets.

Pick a readable text color

typescript