Colore JS

Search documentation

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

darken

darken lowers OKLCH lightness by a percentage of the color’s current lightness. Use it to make a button or accent darker while keeping its hue and chroma before output.

Example

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

colore('#2563eb').darken(10).css(); // '#1451d8'
darken('#2563eb', 10); // '#1451d8'

Syntax

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

Parameters

NameTypeDescription
colorColorInputAny supported CSS color, tagged color object, Color instance or packed RGB number.
amountnumberPercentage of the current lightness to remove. Pass 10 for 10%. 0 keeps the color and 100 gives black.

Returns

The method returns a new Color. The standalone function returns a CSS string that keeps wide-gamut results in Display P3 or OKLCH when needed.

Throws

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

Darken a button for its pressed state

Start from the button’s base color. Here both adjustments return Display P3 because keeping the original chroma moves the results beyond sRGB. Check foreground contrast again if the same text sits on both states.

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

darken('#0f766e', 12); // 'color(display-p3 0.13409 0.38584 0.36213)'
darken('#0f766e', 24); // 'color(display-p3 0.04357 0.31791 0.29604)'

Keep the CSS value for the wider color, or call toGamut('srgb') before hex() when you need a hex token.