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
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.
Related
- Check color contrast in JavaScript for thresholds by use
- contrastRatio to read the score
- ensureContrast to find an adjusted color