Colore JS

Search documentation

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

Get started

Install Colore, then change a button color or check its contrast in a few lines of JavaScript or TypeScript.

Install Colore

npm install colore-js
yarn add colore-js

You need Node.js 20 or later to run the examples locally.

Change a color and check its contrast

import { colore } from 'colore-js';

const button = colore('#2563eb');
console.log(button.lighten(8).hex()); // '#306ff8'
console.log(button.contrastRatio('#fff').toFixed(2)); // '5.17'

The lighter color is a new value. You can still use button for the default state. The second line measures the default blue against white, a ratio of about 5.17:1.

Import one operation

Use colore-js/fn if you need one operation and want the result as CSS.

import { mix } from 'colore-js/fn';

console.log(mix('#ff0000', '#0000ff', 0.5, 'oklab')); // '#8c53a2'

new Color(input) creates the same kind of object as colore(input). Either gives you methods for chaining several changes before you export.