What it does
chroma.js is a JavaScript library for colour conversion, manipulation and scales. It reads several colour formats and provides functions for interpolation, lightness adjustment and formatted output.
Install chroma-js and import the library. A colour can then pass through transformations such as darkening or saturation adjustment before being returned as a hex value.
For a chart, build a scale from chosen colours and set its numeric domain to match the data. Choose an interpolation space such as RGB, Lab or LCh; that choice affects the colours between the endpoints. Gamma shifts the scale’s centre, while lightness correction helps distribute brightness more evenly.
Some conversions produce colours outside the RGB range. The clipped() check identifies when channel values have been limited, which is useful when preserving a strong brand colour matters.
The library uses a BSD licence requiring retained notices. Its bundled ColorBrewer colours carry separate Apache 2.0 terms.
Strengths
- A browser build and npm package support different project setups.
Watch out for
- Changing interpolation space can noticeably change intermediate colours.
Best for
- Developers generating colours from chart values or design parameters
Sources
- chroma.js API documentation (Oct 27, 2026)
- chroma.js repository and quick start (Oct 27, 2026)
- chroma.js licence (Oct 27, 2026)
