Home
Culori is a color library for JavaScript that supports most color spaces and formats defined in the CSS Colors Level 4 spec (named colors, hex colors with 3 to 8 digits, RGB, HSL, HWB, Lab and LCh), plus additional color spaces.
It handles color differences, interpolation, gradients, blend modes and more.
Another JS color library?
Mike Bostock's d3-color, and Gregor Aisch's chroma.js are two excellent, robust libraries that provide most of what you need for working with colors on the web. The Resources section for even more libraries you can try.
Culori does a few things differently:
- The API is function-oriented rather than fluent. Colors are represented as plain JavaScript objects you pass through a series of functions.
- On the
alpha
channel, the library doesn't equate anundefined
value with an opaque color, but rather with a color for which we don't care about the opacity. This gives you the opportunity to interpretundefined
as you see fit. The hex string #ff0000 should probably be rendered as fully opaque red, but for running functions on colors it's useful to discern #ff0000 from #ff0000ff — the former has an implicit alpha of 1, while for the latter it's explicit.