Chroma.js is a lightweight, zero-dependency JavaScript library for comprehensive color conversions and generating sophisticated color scales. Currently at v3.2.0, the library sees a consistent, though not rapid, release cadence, addressing bugs and introducing new features periodically. Its core strength lies in supporting a wide array of color models including RGB, HSL, HSV, Lab, Lch, Oklab, and Oklch, alongside modern CSS color syntax. Key differentiators include its powerful color scale generation capabilities, allowing for custom domains, quantile-based scaling, logarithmic scales, and improved interpolation modes like Lab/Lch for visually smoother transitions, distinguishing it from simpler color utilities. It also provides access to Color Brewer palettes.
npm install chroma-jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic color creation, manipulation (darken, brighten), and the creation of linear and custom-domain color scales with different interpolation modes, including modern CSS color handling.
Migrate `require('chroma-js')` statements to `import chroma from 'chroma-js';`. Ensure your project's `package.json` specifies `"type": "module"` for ESM, or use a bundler that correctly handles ESM.Update your code to expect modern CSS color string outputs from `color.css()`. If you require legacy CSS formats, consider manually formatting the RGB/RGBA values.
Review usage of `scale.domain` and `scale.range` in versions `>=3.2.0` to ensure they align with the updated behavior of returning all scaled positions. Test your color scales thoroughly.
Refer to the official GitHub repository and Discord channel for the most up-to-date information on the project's status and development.
Change `const chroma = require('chroma-js');` to `import chroma from 'chroma-js';`. Ensure your `package.json` has `"type": "module"` if in a pure ESM Node.js environment.Verify `import chroma from 'chroma-js';` is correct. If using CommonJS, ensure your setup correctly transpiles or handles ESM. Check that `chroma-js` is installed correctly.
Adapt your code to parse or expect modern CSS color strings. If legacy `rgb()/rgba()` is strictly needed, you might need to format the color components manually (e.g., `chroma(color).rgb().join(',')` for RGB values).No dependency data recorded yet.