Colore JS

Search documentation

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

Moving from tinycolor2 to Colore

tinycolor2 was written before CSS had oklch(). Tailwind CSS v4 writes its default colors in OKLCH, and so do current shadcn/ui themes. Pass one of those colors to tinycolor2 and it doesn't throw an error. It returns black.

import tinycolor from 'tinycolor2';

tinycolor('oklch(0.6 0.2 260)').isValid();     // false
tinycolor('oklch(0.6 0.2 260)').toHexString(); // '#000000'
tinycolor('color(display-p3 1 0 0)').isValid(); // false

Colore reads every CSS Color 4 format, including oklch(), lab(), color() and color-mix(). It's written in TypeScript and ships its own types, where tinycolor2 needs @types/tinycolor2.

import { isValidColor, toHex } from 'colore-js/fn';

isValidColor('oklch(0.6 0.2 260)'); // true
toHex('oklch(0.6 0.2 260)');        // '#2e79f5'
npm install colore-js

The outputs on this page come from tinycolor2 1.6.0 and colore-js 2.0.1, run on December 3, 2026.

Calling Colore instead of tinycolor2

tinycolor2 wraps every color in an object, and you call a format method at the end. Colore's Color class chains the same way. Colore also has plain functions in colore-js/fn that take a color and return a CSS string, hex when the result fits sRGB.

import tinycolor from 'tinycolor2';
import { colore } from 'colore-js';
import { lighten } from 'colore-js/fn';

tinycolor('#2563eb').lighten(10).toHexString(); // '#5484ef'
colore('#2563eb').lighten(10).hex();            // '#3272fb'
lighten('#2563eb', 10);                         // '#3272fb'

The lighter blue differs because tinycolor2 does most of its math in HSL and Colore does it in OKLCH, where a change in lightness keeps the color's hue and chroma.

Method by method

tinycolor2ColoreResult
tinycolor(x).isValid()isValidColor(x)Same for formats tinycolor2 reads. Colore also reads OKLCH, Lab, color() and color-mix().
.toHexString() / .toHex8String()toHex(x)Same. Colore adds the two alpha digits only when alpha is below 1 (#2563eb80), so one call covers both.
.toRgbString()toRgb(x)Same values, written rgb(37 99 235) instead of rgb(37, 99, 235)
.toHslString()toHsl(x)Same values, written hsl(221 83% 53%)
.setAlpha(0.5)setAlpha(x, 0.5)Same color. Colore returns #2563eb80.
.getLuminance()luminance(x)Same
tinycolor.readability(a, b)contrastRatio(a, b)Same WCAG 2 ratio
tinycolor.isReadable(a, b)isReadable(a, b)Same default: WCAG AA for normal text, 4.5:1
tinycolor.mostReadable(bg, list)new Color(bg).isDark() or bestTextColor(bg, list)isDark() gives the same WCAG 2 pick between black and white. bestTextColor picks by APCA. See below.
.isDark() / .isLight()new Color(x).isDark() / .isLight()Different cutoff. Colore's tells you which text color has more contrast. See below.
.lighten(n) / .darken(n)lighten(x, n) / darken(x, n)Different math, OKLCH instead of HSL
.saturate(n) / .desaturate(n)saturate(x, n) / desaturate(x, n)Different math. A saturated result can be wider than sRGB.
.spin(deg)adjustHue(x, deg)Different math, OKLCH hue
.greyscale()grayscale(x)Different. Colore keeps the color's perceived lightness: #707070 for #2563eb, where tinycolor2 gives #888888.
.complement()complement(x)Different, OKLCH hue: #906900 for #2563eb, where tinycolor2 gives #ebad25
.triad()triadic(x)Different, OKLCH hue
tinycolor.mix(a, b, 50)mix(a, b, 0.5)Different. tinycolor2 mixes sRGB values and Colore mixes in OKLab, so #2563eb and #facc15 give #909880 and #90a3ad. Pass 'srgb' as the fourth argument to get tinycolor2's result. Colore takes 0 to 1.
.analogous(), .tetrad(), .splitcomplement(), .monochromatic()None in 2.0For shades of one color, use palette.

All the Colore names in the middle column are exports of colore-js/fn except isDark and isLight, which are methods on the Color class.

Black or white text

mostReadable returns the candidate with the best WCAG 2 ratio. In Colore, isDark() makes the same choice between black and white, apart from colors right at the crossover point. The color it picks always reaches at least 4.58:1, which passes WCAG AA for normal text.

tinycolor.mostReadable('#3b82f6', ['#000000', '#ffffff']).toHexString(); // '#000000'
colore('#3b82f6').isDark() ? '#ffffff' : '#000000';                       // '#000000'
bestTextColor('#3b82f6');                                                  // '#ffffff'

bestTextColor picks by APCA, a newer contrast method that tinycolor2 doesn't have. It often picks white on saturated mid-tones like this blue, where WCAG 2 picks black. Across a grid of 4,096 background colors (16 levels per RGB channel), it picked differently from mostReadable on 1,151, about 28%. Black or white text compares the two methods on every Tailwind 500 shade.

isDark tells you which text color to use

tinycolor2 calls a color dark when its perceived brightness is under 128 out of 255. Colore calls it dark at a relative luminance of 0.179 or less, the point where white text starts to have more WCAG 2 contrast than black. The two cutoffs disagree on 627 of the same 4,096 colors, about 15%. If you switch text color on isDark(), those colors get a different text color after you move to Colore, and it's the one with more contrast.

What changes when you lighten

tinycolor2 adds points of HSL lightness. HSL lightness doesn't track what you see, so lighten(20) takes a different-size step on each color and lowers its chroma. Colore moves 20% of the way to white in OKLCH on every color, and keeps the hue and chroma.

Tailwind 500 shadeChromaAfter tinycolor2 lighten(20)After Colore lighten(x, 20)
yellow #eab3080.1620.1410.162
violet #8b5cf60.2190.0880.219
blue #3b82f60.1880.0910.188
red #ef44440.2080.1010.208
Violet 500
tinycolor2
Colore

On violet, blue and red, tinycolor2's lighter shade keeps less than half the chroma of the original, which is why it looks washed out. Colore's lighter violet is still the same violet, and it stays that way in hex: toHex(lighten('#8b5cf6', 20)) is #a276ff, with chroma 0.196 against tinycolor2's 0.088. Before you convert, Colore's functions write a color that's more vivid than sRGB as oklch() or color(display-p3 …), which current browsers render. When you need hex, call toHex, or .toGamut('srgb').hex() on the Color class to keep the hue closer. See Gamut and CSS output.

The same amount moves the color a different distance in each library, so don't copy the numbers across. Pick new amounts by eye, or replace hand-picked hover colors with generateStates.

When to switch

tinycolor2 is the smaller package, at 5.4 kB gzipped (bundlephobia). In Colore, toHex alone from colore-js/fn is about 10 KiB gzipped, because it brings the parser with it, and the Color class is about 18 KiB, measured with Rollup and Terser (details).

Switch when your app reads OKLCH or Display P3 colors, when you want lighter and darker shades that keep their color, or when you need contrast repair and theme generation, which tinycolor2 doesn't have.

If designers signed off on colors that tinycolor2 calculated, switching changes them. Generate both sets and compare before you replace stored values. To see the shades and theme Colore makes from your brand color, open it in the palette generator or the theme generator.