Colore JS

Search documentation

Find a function or jump to a section.
v2.0.1

isReadable

isReadable checks whether a text and background pair meets a contrast target. Use it when your code needs a boolean for WCAG AA, WCAG AAA or a project-specific target.

Example

import { colore } from 'colore-js';
import { isReadable } from 'colore-js/fn';

colore('#767676').isReadable('#fff');        // true
isReadable('#767676', '#fff', 'aaa');        // false

Syntax

colore(textColor).isReadable(background: ColorInput | Color, options?: ReadableOptions): boolean
isReadable(textColor: ColorInput, background: ColorInput, options?: ReadableOptions): boolean

Parameters

NameTypeDescription
textColorColorInputThe foreground color.
backgroundColorInputThe color behind the foreground.
optionsReadableOptionsA level shorthand ('aa' or 'aaa', also accepted in uppercase) or an object with intent, algorithm, and either level or target. The default is WCAG AA for normal text.

Returns

true if the raw contrast reaches your target, otherwise false.

Throws

A ColorError for invalid colors, unknown options, unsupported values, or an options object with both target and level.

Check contrast for large text

import { isReadable } from 'colore-js/fn';

isReadable('#949494', '#fff', { intent: 'largeText' }); // true
isReadable('#949494', '#fff');                          // false

WCAG AA requires 3:1 for large text and 4.5:1 for body text. With { algorithm: 'apca' }, the presets are Colore thresholds expressed in Lc. Use target to apply a threshold from your own project.