Colore JS

Search documentation

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

Color constructor and inputs

Create a Color when you have a CSS string, RGB channels or a color you want to edit. colore(input) and new Color(input) accept the same values and give you the same methods.

Example

import { Color, colore } from 'colore-js';

console.log(colore('rebeccapurple').hex()); // '#663399'
console.log(new Color({ r: 37, g: 99, b: 235 }).hex()); // '#2563eb'

Syntax

new Color(input: ColorInput | Color): Color
colore(input: ColorInput | Color): Color

Parameters

NameTypeDescription
inputColorInput | ColorA supported CSS color, a packed RGB integer, a channel object or a Color.

Returns

A Color with methods for editing, conversion and contrast. Passing an existing Color copies it.

Throws

A ColorError if the value has unsupported syntax, missing channels or invalid units. For values from a form, use Color.try if a fallback is enough.

Pass normalized RGB from a picker

Untagged RGB objects use 0–255. If your picker gives you 0–1 channels, mark them with space: 'srgb'. Use alpha for opacity. Untagged RGB, HSL, HSV and HWB objects also accept a.

import { Color } from 'colore-js';

const swatch = new Color({ space: 'srgb', r: 0.5, g: 0.25, b: 1 });
console.log(swatch.hex()); // '#8040ff'
console.log(new Color(0x2563eb).hex()); // '#2563eb'

Use explicit tags for Lab, LCH, OKLab, OKLCH, XYZ and Display P3. Lab and OKLab share channel names, so the tag tells Colore which units you mean.