Colore JS

Search documentation

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

grayscale

grayscale turns a color into a neutral gray at the same OKLCH lightness. It keeps the color’s opacity, which is handy when the original is a translucent overlay.

Example

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

colore('#0f766e').grayscale().css(); // '#666666'
grayscale('#0f766e'); // '#666666'

Syntax

colore(color).grayscale(): Color
grayscale(color: ColorInput): string

Parameters

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

Returns

The method returns a new Color. The standalone function returns the gray as a CSS string. With ordinary sRGB colors, the result is hex.

Throws

A ColorError if the input is an invalid color.

Make a transparent overlay neutral

Use the same lightness and opacity on a neutral overlay. The last two digits of the hex result encode the original alpha rounded to one byte.

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

grayscale('#2563eb80'); // '#70707080'
grayscale('rgb(37 99 235 / 25%)'); // '#70707040'

For an accent that still has some color, use desaturate with a percentage below 100.