Skip to main content

contrast

function

Get a contrasting color (black or white) for text readability. Uses WCAG relative luminance calculation to determine the best contrast.

function contrast(color: string): '#ffffff' | '#000000'

Import

import { contrast } from '@modular/sdk';

Notes

returns
'#000000' for light backgrounds, '#ffffff' for dark backgrounds
throws
Error if the color format is invalid
example
```ts contrast('#ffffff') // => '#000000' contrast('#000000') // => '#ffffff' contrast('#ff0000') // => '#ffffff' ```