Colore JS

Search documentation

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

toOklab

toOklab converts a color to a CSS oklab() string. OKLab has a lightness channel and two opponent color channels, which are useful for comparing or mixing colors.

Example

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

colore('#7c3aed').oklab(); // 'oklab(0.54134 0.09638 -0.22697)'
toOklab('#7c3aed'); // 'oklab(0.54134 0.09638 -0.22697)'

Syntax

colore(color).oklab(): string
toOklab(color: ColorInput): string

Parameters

NameTypeDescription
colorColorInputAny supported CSS color, tagged color object, Color instance or packed RGB number.

Returns

An oklab(l a b) string with each channel rounded to five decimals. The output includes slash-separated alpha when the input is translucent. Conversion keeps colors outside sRGB.

Throws

A ColorError if the input color is invalid.

Read the numeric lightness of a brand color

The class method toOklab() returns numbers for calculations. The string form is for CSS output and rounds its channels.

import { colore } from 'colore-js';

const color = colore('#0f766e');
Number(color.toOklab().l.toFixed(3)); // 0.511
color.oklab(); // 'oklab(0.51094 -0.08552 -0.00958)'

Use OKLCH when you want to work with chroma and hue in place of the two opponent channels.

  • toOklch to read chroma and hue
  • deltaEOK to compare colors in OKLab
  • mix to blend colors in OKLab