Skip to content
party.js logoparty.js logo

ReferenceUtilitiesFunction

color()

Converts a CSS color string to an Oklab color.

function color(input: string | Color): Color;

Converts a CSS color string to a Color.

Accepts hex colors (#f00, #ff5a5f, #ff000080) and the rgb()/rgba(), hsl()/hsla(), oklab() and oklch() functions. A Color passed in is returned unchanged.

Note that named colors are not supported, to minimize bundle size. In particular, transparent is not a valid color input.

inputstring | Color

A CSS color string, or an existing color.

Color

The Oklab color.

PartyJSError

If the string isn’t a supported color.

const cornflowerblue = color("#6495ed");