Skip to content

@kurkle/color

@kurkle/color parses CSS color strings and lets you read, convert and manipulate the result through a small Color class. It supports hex, named colors, rgb(), hsl(), hwb(), hsv() and oklch().

Terminal window
npm install @kurkle/color
import { Color } from "@kurkle/color"
const color = new Color("oklch(0.7 0.15 200)")
color.valid // true
color.hexString() // "#00B9C3"
color.darken(0.2).rgbString() // "rgb(0, 148, 156)"

See Parsing for every supported syntax, Formatting for turning a color back into a string, and Transforming for the mutating methods like mix, lighten and rotate.