Colore JS

Search documentation

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

Color spaces and ranges

An RGB triplet from a canvas can use 0–255, while a picker may give you 0–1. Choose the channel space and units before you move values between tools.

Look up the channel ranges

Input or output spaceTypical channel units
Untagged RGB object, toRgb()Encoded 0–255 RGB and 0–1 alpha
'srgb', 'p3'Encoded 0–1 RGB
'srgb-linear'Linear-light RGB. Use with toObject() and toArray().
'hsl', 'hsv', 'hwb'Hue in degrees and the remaining channels on a 0–100 scale
'lab', 'lch'D50 white point and lightness 0–100. LCH hue uses degrees.
'oklab', 'oklch'Lightness 0–1. OKLCH hue uses degrees.
'xyz'XYZ with a D65 white point

Alpha runs from 0 to 1 in each space. These are typical values. Numeric conversions can give you channels outside those ranges for wide-gamut colors.

Read channels for a picker

Use toArray('srgb') for encoded unit-range RGB followed by alpha.

import { colore } from 'colore-js';

const blue = colore('#2563eb');
console.log(blue.toArray('srgb').map(value => Number(value.toFixed(3))));
// [0.145, 0.388, 0.922, 1]

Use toObject('srgb') if you need to pass that color back to Colore with its space attached. Use toRgb() when your consumer expects 0–255 integer channels.

Mix colors in the space you want

import { colore } from 'colore-js';

console.log(colore('#ff0000').mix('#0000ff', 0.5, 'oklab').css()); // '#8c53a2'

OKLab is a good starting point for a visual transition. Use sRGB when you need to match an existing sRGB blend.