Color.js is a color conversion and modification library created by two of the editors of the CSS Color specifications: Lea Verou and Chris Lilley.
They continue to work on it, but are also joined by an exceptional small grassroots team of co-maintainers.
Features
Color space agnostic: Each color object is basically a list of coords and a color space reference. Operations are color space agnostic.
Modules for a wide variety of color spaces,
including Lab/LCh, OKLab/OKLCh,
sRGB and friends (HSL/HSV/HWB), Display P3,
Jzazbz, REC.2100 and many more.
Doesn't gloss over color science: Actual gamut mapping instead of naïve clipping,
multiple DeltaE methods (76, CMC, 2000, Jz),
multiple chromatic adaptation methods (von Kries, Bradford, CAT02, CAT16),
all with sensible defaults
Up to date with CSS Color 4: Every CSS Color 4 format & color space supported for both input and output, whether your browser supports it or not.
Readable, object-oriented API: Color objects for multiple operations on the same color, and static Color.something() functions for one-off calculations
Modular & Extensible: Use only what you need, or a bundle. Client-side or Node. Deep extensibility with hooks.
You can use properties to modify coordinates
of any color space and convert back
letcolor = newColor("slategray"); color.lch.l = 80; // Set coord directly in any color space color.lch.c *= 1.2; // saturate by increasing LCH chroma by 20% color.hwb.w += 10; // any other color space also available
To modify coordinates in any color space you use color.set() and color.setAll():
letcolor = newColor("slategray");
// Multiple coordinates color.set({ "lch.l":80, // set lightness to 80 "lch.c":c=>c * 1.2// Relative manipulation });
// Set single coordinate color.set("hwb.w", w=>w + 10);
Coordinates of the color's color space are available without a prefix:
letcolor = newColor("slategray").to("lch");
// Multiple coordinates color.set({ l:80, // set lightness to 80 c:c=>c * 1.2// Relative manipulation });
letcolor = newColor("slategray"); color.lch.l = 80; // Set coord directly in any color space color.lch.c *= 1.2; // saturate by increasing LCH chroma by 20% color.hwb.w += 10; // any other color space also available
Coordinates of the color's color space are available without a prefix:
letcolor = newColor("slategray").to("lch"); color.l = 80; // Set LCH lightness color.c *= 1.2; // saturate by increasing LCH chroma
letcolor = newColor("p3", [0, 1, 0]); color.steps("red", { space:"lch", outputSpace:"srgb", maxDeltaE:3, // max deltaE between consecutive steps steps:10// min number of steps });
This is a set of (currently 10) web components for building color-related apps (the first library of its kind to our knowledge).
It includes things like color pickers, color charts, interactive color scales, and more.
A research project which aims to analyze designer-created color palettes in a variety of color spaces,
both to document patterns (e.g. what hue names are most popular?)
and to understand what makes aesthetically pleasing color scales.
Color.js is a free and open source project, developed on a volunteer basis.
We very recently started an Open Collective so you can fund Color.js's development.
If your company depends on Color.js in any way, it is in your best interest to ensure its future is sustainable.
Once there are enough sponsors, we plan to feature them prominently on our website and README, so if you want to be among the first ones to get your name in there, now’s the chance!