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

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

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

API

Valeur de retour

La valeur retournée par cet util.

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

Usage

Exemples

Extraits de code prêts à coller.

Pick a readable text color

typescript