Colore JS

Search documentation

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

setOklch

setOklch sets one or more OKLCH channels to the values you choose. The channels you omit keep their current values, and opacity is preserved.

Example

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

colore('#2563eb').setOklch({ l: 0.62 }).oklch(); // 'oklch(0.62000 0.21521 262.88)'
setOklch('#2563eb', { l: 0.62 }); // 'color(display-p3 0.29547 0.47723 0.98934)'

Syntax

colore(color).setOklch(channels: OklchChannels): Color
setOklch(color: ColorInput, channels: OklchChannels): string

Parameters

NameTypeDescription
colorColorInputAny supported CSS color, tagged color object, Color instance or packed RGB number.
channelsOklchChannelsAn object with at least one of l, c and h.
channels.lnumberLightness from 0 to 1. Pass 0.62 for 62%.
channels.cnumberChroma from 0 to 1. CSS 100% chroma corresponds to 0.4.
channels.hnumberHue in degrees. Any finite angle wraps into one turn.

Returns

The method returns a new Color. The function returns a CSS string in hex, Display P3 or OKLCH. Colore keeps the requested channels before output and leaves gamut mapping to you.

Throws

A ColorError if the color is invalid, the channel object is empty or contains an unknown key, a channel is out of range, or chroma is added to a gray without supplying its hue.

Tint a neutral gray with a specific hue

Set both hue and chroma on a gray. Start low on chroma when you want the new color to read as a neutral.

import { colore } from 'colore-js';

colore('#ddd').setOklch({ c: 0.03, h: 75 }).oklch(); // 'oklch(0.89755 0.03000 75.00)'
colore('#ddd').setOklch({ c: 0.03, h: 75 }).css(); // '#e9dbc8'

Use the method with .oklch() when you want to read the new coordinates. Use toGamut('srgb') when a color must fit in sRGB before you export it.