chroma-js
chroma-js — a library for colour manipulation and palette generation.
Supports conversion between RGB, HSL, HSV, LAB, LCH, OKLab, OKLch, and
hex. The chroma.scale() helper interpolates smoothly between any number
of colour stops in a chosen colour space, making it ideal for mapping
continuous values (noise, distance, temperature) to perceptually uniform
colour gradients.
Imported as the default export:
const chroma = require(‘chroma-js’)
chroma is both a callable constructor and a namespace — static methods
such as chroma.scale() and chroma.mix() are attached directly to it.
See also:
interface ColorA chroma-js Color object returned by the chroma(...) constructor and by
most static methods. Immutable — every mutating method returns a new Color.
interface ScaleA colour scale returned by chroma.scale(). Call it as a function with
a value in [0, 1] (or your custom domain) to get a Color at that position.
const chroma = require('chroma-js');var scale = chroma.scale(['#fff', '#00f']).mode('lab');var midColor = scale(0.5); // Color at the midpointChromaStatic
Section titled “ChromaStatic”interface ChromaStaticConstruct a Color from a variety of input formats:
- Named CSS colour:
chroma('red'),chroma('royalblue') - Hex string:
chroma('#ff0000'),chroma('ff0000') - RGB values:
chroma(255, 0, 0)orchroma([255, 0, 0]) - Explicit colour space:
chroma(270, 0.5, 0.5, 'hsl'),chroma(50, 25, 10, 'lab')
const chroma = require('chroma-js');var red = chroma('red');var blue = chroma('#3498db');var green = chroma(0, 200, 100);var lab = chroma(50, -10, 30, 'lab');See also: