Color Value Tools
A comprehensive utility library for parsing, converting, manipulating, and analyzing color values across all major color models — hex, RGB, HSL, HSV, HWB, Lab, LCH, Oklab, Oklch, CMYK, Display P3 — plus CSS variables and named colors. Zero dependencies.
Features
- Universal parser —
normalizeColor()accepts hex (3/4/6/8-digit),rgb()/rgba(),hsl()/hsla(),hwb(),oklch()/oklcha(),color(display-p3 ...), CSS named colors (all 148), and plain{r,g,b}/{h,s,l}objects - Conversions — every path between hex, RGB, HSL, HSV, HWB, Lab, LCH, Oklab, Oklch, CMYK, Display P3; all round-trip accurate
- Manipulation —
lighten,darken,saturate,desaturate,invertColor,grayscale,setAlpha,rotateHue,adjustHexBrightness - Mixing & Interpolation —
mixColorsandinterpolateColorsin 6 color spaces with 4 hue interpolation modes;createColorScaleacross multiple anchor colors with custom positions;midpointColorfor a perceptual midpoint - Color Harmonies —
complement,triadic,analogous,splitComplementary,tetradic - Palette Generation —
colorShades,monochromatic,tints,shades,tones,randomColor— all Oklab-accurate where applicable - WCAG Accessibility —
relativeLuminance,contrastRatio,wcagLevel,bestTextColor,bestContrastColor,bestContrastPalette,isReadableOnBackground(solid, semi-transparent, and gradient backgrounds) - Color Blindness Simulation — protanopia, deuteranopia, tritanopia using Vienot 1999 matrices on linear RGB
- Perceptual color distance —
colorDeltaEimplementing the full CIEDE2000 formula - CSS Formatting —
toHslString,toHwbString,toOklchString,toColorP3String - Memoization cache —
normalizeColorCachedcaches parsed results in memory;getCacheStats,clearColorCache,enableCache/disableCache - Lazy generator functions —
generateGradientColors,generateTints,generateShadesfor iterating without pre-allocating arrays - CLI (
cvt) — inspect any color from the terminal: full info, all conversions, WCAG contrast, shades, harmonies, nearest named color - Zero dependencies — no runtime deps; ships as tree-shakeable ESM + CommonJS