chroma.js: a zero-dependency JavaScript library for color scales and conversions
JavaScript library for all kinds of color manipulations
At a glance
- What is it?
- Gregor Aisch's library keeps a small dependency-free surface for reading, converting and scaling colors, ships a light build alongside the full one.
- Who is it for?
- The library's shape has stayed narrow for years: a chainable color object, a scale function with selectable interpolation modes and domain strategies, and nothing that requires a build step of your own. If you need categorical palettes that pass through Lab instead of RGB, or quantile and log domains over unevenly distributed values, the parts that matter are in the scale function and you can read that code before depending on it.
- Can I use it commercially?
- Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
- Is it still maintained?
- Yes. The repository last received commits 9 days ago.
- What is it written in?
- Mainly JavaScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- gka/chroma.js10,604 ★ · +6
| Repository | 2026-10-07 | 2026-11-25 |
|---|---|---|
| gka/chroma.js | 10.6k | 10.6k |
6 Stars in the last 49 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
What chroma.js actually covers
chroma.js is described in its own package metadata as a JavaScript library for color conversions, and the repository description widens that to all kinds of color manipulations. The scope in practice is narrower and more useful than either phrase suggests. It parses colors from strings and numbers, converts them between spaces including RGB, Lab and Lch, exposes arithmetic-style operations on a color object, and builds continuous and discrete scales from arrays of colors.
The distinguishing detail is the dependency count. The readme calls it a small-ish zero-dependency library and links a bundle size badge, which is a claim worth taking seriously for a package that ends up in visualization code and design tools. There is no color space conversion table to configure, no plugin registry, and no color management profile to load first. You pass a color in and you get a color out.
The author is Gregor Aisch, whose name appears in the package metadata as both author and sole maintainer, with vis4.net listed as his web address and the documentation site at gka.github.io/chroma.js.
Installing and importing
Installation is a single package name, and the readme shows the same line twice, once in a fenced block and once as an indented command for the node.js section:
npm install chroma-jsThe package declares itself an ES module through the type field in its package metadata, and the documented import is a default import:
import chroma from "chroma-js";The export map is more interesting than a single entry point. It resolves the bare specifier to index.js for import and to a CommonJS file under dist for require, and it also publishes a light variant under a subpath:
".": {
"import": "./index.js",
"require": "./dist/chroma.cjs"
},
"./light": {
"import": "./index-light.js",
"require": "./dist/chroma-light.cjs"
},That second entry is the answer to a question bundle analyzers ask constantly. The light build is published as a separate subpath so code can opt into it. The root of the repository carries matching files for each distribution shape, including UMD builds for script tags.
Development tooling is pinned to pnpm rather than npm, with the package manager field naming [email protected], and a pnpm lockfile sits at the repository root. That only matters if you intend to work on the library itself, but it does mean the documented install and the maintainer's own install path differ.
Chainable color operations
The core object is immutable and chainable. Each operation returns a new color rather than mutating the one you started with, which is what makes it safe to hold a base color and derive several variants from it. The readme opens with the shortest possible example:
chroma('#D4F880').darken().hex(); // #a1c550Two things are worth noting in that line. Input parsing is forgiving, so a hex string with a leading hash is enough to get a working color object, and output formatting is explicit, because nothing is rendered until you ask for a string representation with a call like hex().
Scales, interpolation modes and domains
Scales are the reason most projects reach for this library. A scale takes colors and returns a function that maps a numeric input to an interpolated color:
scale = chroma.scale(['white', 'red']);
scale(0.5).hex(); // #FF7F7FInterpolation happens in a chosen color space. Switching modes is a single call, and the readme pairs the suggestion with a reason:
chroma.scale(['white', 'red']).mode('lab');The readme states that Lab/Lch interpolation looks better than RGB.
Scales also accept named palettes and custom class boundaries. Compute quantile breaks from the data with `chroma.limits`, then pass those breaks to `classes`:
const quantileBreaks = chroma.limits(myValues, 'q', 7);
const quantileScale = chroma.scale('RdYlBu').classes(quantileBreaks);For positive values spanning orders of magnitude, compute logarithmic class breaks in the same way:
const logBreaks = chroma.limits([1, 100000], 'l', 7);
const logScale = chroma.scale(['lightyellow', 'navy']).classes(logBreaks);These examples create discrete classes; use a continuous scale with an appropriate transformation when a continuous logarithmic mapping is needed. The README contains older extra arguments to `domain`, but the current implementation accepts the domain array only. A single linear scale across a domain like that collapses almost every useful value into the first color.
Repository layout and the build pipeline
The tree is organized around a source directory and a build output directory, with configuration files sitting at the root next to the entry points. Source modules are grouped by role rather than by feature, and the package export map exposes those groups directly, with separate subpaths for colors, generator, interpolator, io, ops and utils under src. That layout means you can import a single operation module instead of the whole library if you need to keep a build narrow, and the grouping tells you where a given operation lives.
The build is a Rollup configuration driven by three scripts declared in the package metadata:
"build": "rollup -c && cross-env DEV=1 rollup -c ",
"docs": "cd docs && make",
"test": "vitest",Each stage runs twice in the build script, once normally and once with a development flag set through cross-env. Tests run under vitest, with a config file of the same name at the root, and there is a separate update mode for refreshing snapshots. Linting is split between prettier for formatting checks and eslint for the source, with the check list covering the entry points, src and the config files.
The docs are not generated by a JavaScript toolchain. The docs script changes into a docs directory and runs make, and a separate preview script runs make twice, once to build and once to preview. The readme also points at a static markdown version of the interactive documentation, which is useful when you want to read the API reference without a browser. One stale detail is worth flagging: the build instructions in the readme describe compiling coffee-script source files, while the package scripts build with rollup, so those instructions describe an earlier era of the build.
Release history and maintenance reality
The last three published releases are v3.1.3 (2025-10-29), v3.1.4 (2025-11-27) and v3.2.0 (2025-11-28), while package.json on the default branch already reads version 3.3.0.
The repository itself is not archived, carries 64 open issues, and its last push is dated 2026-10-24, so the code is being touched. The readme preempts the more anxious question in its own FAQ section, where the maintainer explains that gaps between commits reflect a working library rather than an abandoned one, and points contributors to the project's discord channel. Licensing follows the same pattern of statements in prose: the readme describes releases under the BSD license, with versions before 0.4 under the GPL, while the API metadata carries no machine-readable license identifier, so check the LICENSE file in the repository if that distinction matters to your compliance process.
Editorial conclusion
The library's shape has stayed narrow for years: a chainable color object, a scale function with selectable interpolation modes and domain strategies, and nothing that requires a build step of your own. If you need categorical palettes that pass through Lab instead of RGB, or quantile and log domains over unevenly distributed values, the parts that matter are in the scale function and you can read that code before depending on it. Pin the version you test against, keep the full build rather than the light one unless you have measured the bundle.
Frequently asked questions
How do I build a color scale in chroma.js?
Pass an array of colors to chroma.scale, and it returns a function that maps a number to a color. For example, chroma.scale(['white', 'red']) produces a ramp, and calling the result with 0.5 gives the midpoint, which converts to #FF7F7F. Pick the interpolation space with mode, use a named scheme such as 'RdYlBu' for palettes from ColorBrewer, and pass a domain when your input values are unevenly distributed, for example chroma.scale('RdYlBu').domain(myValues, 7, 'quantiles').
Should I import chroma-js from the root or the light build?
The root entry point loads the full library, and the light build is published under the chroma-js/light subpath. The export map resolves each subpath for both import and require, so the choice is a specifier change rather than a bundler alias.
Why does my gradient look dull in the middle?
The usual cause is interpolating in RGB. Averaging channel values does not track perceived brightness, so a light color fading to a dark one passes through a grayish midpoint. Select a perceptual space for the scale with mode('lab'). The readme calls out Lab and Lch interpolation specifically as producing better results than RGB for ramps like white to red.
What is the newest chroma.js release?
The newest published release is v3.2.0, from 2025-11-28, although package.json on the default branch already reads version 3.3.0.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/gka-chroma-js)Star history chart for your README
[](https://hysenlabs.com/projects/gka-chroma-js)Was this useful?