Colore JS

Search documentation

Find a function or jump to a section.
v2.0.1

Colore 2.0

Colore 2.0 is a complete rebuild. It works in OKLCH, so colors change the way people see them; it keeps text readable without you checking every pair; and it turns one brand color into a full light and dark theme for the stack you already use. It is still zero dependencies, fully typed, and small enough to ship to the browser: one function from colore-js/fn is about 10 KiB gzipped.

What is new

Modern CSS colors

Parse modern formats such as OKLCH and Display P3, and evaluate supported color-mix() expressions. Lighten and darken in OKLCH, or choose the space you want when you mix. Use css() to keep a wider color or toGamut() to map it. Color spaces

Readable by default

ensureContrast searches for a foreground that passes your WCAG 2 or APCA target. Check its success flag before applying the result. audit checks a whole palette or a globals.css, and fixCssVariables repairs it.

A complete theme from one color

generateSystem builds brand, surface, text, border, status and chart colors for light and dark mode, all checked for contrast. Export it as CSS variables, a Tailwind CSS v4 theme, a shadcn/ui globals.css or design tokens.

Edit the theme you already have

Use inspectCssTheme to read the theme, applyThemeToCss to rebrand it, and adjustCssVariables to tune selected colors.

Built for coding agents

Run npx colore-js init to install the Colore skill for Claude Code, Cursor and Codex. The CLI adds inspect, theme --apply, adjust, set, extract and preview for working with theme files. Coding agents and CLI

Palettes and chart colors

palette builds shade ramps that contain your brand exactly. categoricalColors gives chart series that stay distinct, including for color-blind readers.

Upgrading from 1.x

2.0 has a new API, so plan a short migration. Most code maps directly:

1.x2.0
hexToRgb, rgbToHsl and other conversionscolore(color).rgb(), .hsl(), .oklch(), or toRgb, toHsl from colore-js/fn
lightenColor, darkenColor, saturateColor, desaturateColorlighten, darken, saturate, desaturate
invertColor, setAlphaValue, blendColorsinvert, setAlpha, mix
getContrastRatio, getLuminancecontrastRatio, luminance
complementaryColor, triadicColors, single-hue rampscomplement, triadic, palette
generateInterpolatedColorsinterpolate or scale
isValidHex, isValidRgb and other validatorsisValidColor
parseColorToRgba, detectColorFormatparse, detectFormat

analogousColors, tetradicColors, enhanceColor, generateRandomColor, the CSS-variable DOM helpers, BlendingModes and ColorFormats are gone.

Three changes to know about:

  • Lighten, darken and saturate now work in OKLCH, so the same amount gives a slightly different, more even result than 1.x.
  • Functions from colore-js/fn return CSS strings: hex when the color fits sRGB, oklch() or color(display-p3 …) when it doesn't.
  • Invalid input and unknown options throw a ColorError that names the fix, instead of returning a guessed color.
import { colore } from 'colore-js';
import { lighten, contrastRatio } from 'colore-js/fn';

colore('#2563eb').lighten(8).hex(); // '#306ff8'
lighten('#2563eb', 8);              // '#306ff8'
contrastRatio('#111827', '#ffffff'); // ≈ 17.74

The 1.x documentation stays online.

Next steps