Colore JS

Search documentation

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

invert

invert gives you a color negative. It flips the gamma-encoded sRGB channels, so black becomes white, red becomes cyan, and alpha stays as it was.

Example

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

colore('#ff0000').invert().css(); // '#00ffff'
invert('#ff0000'); // '#00ffff'

Syntax

colore(color).invert(): Color
invert(color: ColorInput): string

Parameters

NameTypeDescription
colorColorInputAny supported CSS color, tagged color object, Color instance or packed RGB number.

Returns

The method returns a new Color. The function returns a CSS string, with hex for an sRGB result and a wider CSS format when needed.

Throws

A ColorError if the input color is invalid.

Invert a translucent icon color

Apply the channel inversion to the icon’s color and keep its alpha. This changes the painted color while retaining how much of the backdrop shows through.

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

invert('#11223380'); // '#eeddcc80'
invert('#000000'); // '#ffffff'

Use complement when you want a partner on the OKLCH hue wheel. To choose a text color for a background, check contrast against that background.