Colore JS

Search documentation

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

desaturate

desaturate reduces OKLCH chroma by a percentage. It keeps lightness and hue before output, so a muted accent still belongs to the same palette.

Example

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

colore('#2563eb').desaturate(30).css(); // '#3f6cc7'
desaturate('#2563eb', 30); // '#3f6cc7'

Syntax

colore(color).desaturate(amount: number): Color
desaturate(color: ColorInput, amount: number): string

Parameters

NameTypeDescription
colorColorInputAny supported CSS color, tagged color object, Color instance or packed RGB number.
amountnumberPercentage of the current chroma to remove. Pass 30 for 30%. 0 keeps the color and 100 removes all chroma.

Returns

The method returns a new Color. The standalone function returns a CSS string, using hex, Display P3 or OKLCH as appropriate for the resulting color.

Throws

A ColorError if the color is invalid or the amount is outside 0–100, nonfinite, or strictly between 0 and 1.

Make a quieter accent and a matching gray

Try a partial reduction for a muted accent. Use 100 for a neutral with the same OKLCH lightness. Check contrast on the actual background if you use either as text.

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

desaturate('#db2777', 60); // '#a9677b'
desaturate('#db2777', 100); // '#7e7e7e'

Repeated changes compound. A single 60 adjustment keeps 40% of the starting chroma. Use setOklch when every token needs the same chroma value.