Colore JS

Search documentation

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

scale

scale builds a color scale between two endpoints. Use it for a stepped gradient or ordered data. The default OKLab interpolation gives you stops spaced evenly along the path in that space.

Example

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

colore('#ef4444').scale('#3b82f6', { steps: 3 }).map((color) => color.css());
scale('#ef4444', '#3b82f6', { steps: 3 });
// ['#ef4444', '#a775a5', '#3b82f6'] from either line

Syntax

colore(from).scale(to: ColorInput | Color, options?: ScaleOptions): Color[]
scale(from: ColorInput, to: ColorInput, options?: ScaleOptions): string[]

Parameters

NameTypeDescription
from, toColorInputStart and end colors. The method can take a Color.
options.stepsnumberThe number of output colors, including endpoints. Defaults to 5.
options.spaceInterpolationColorSpace'oklab' by default. Also accepts 'oklch', 'srgb', 'p3', 'hsl', 'lab' and 'lch'.

Returns

The method returns Color[]. The function returns CSS strings, including Display P3 or OKLCH when a color falls outside sRGB.

Throws

A ColorError for an invalid color, unsupported space, unknown option, or step count under two or with a fractional part.

Create seven stops for an ordered chart

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

scale('#ef4444', '#3b82f6', { steps: 7 });
// ['#ef4444', '#d85c69', '#c16b88', '#a775a5', '#8b7cc0', '#6a80db', '#3b82f6']
#ef4444
#d85c69
#c16b88
#a775a5
#8b7cc0
#6a80db
#3b82f6