Colore JS

Search documentation

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

lighten

lighten moves a color toward white in OKLCH while keeping its hue. Use it for a hover state or when you want a lighter version of a swatch.

Example

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

colore('#2563eb').lighten(8).hex(); // '#306ff8'
lighten('#2563eb', 8);              // '#306ff8'

Syntax

colore(color).lighten(amount: number): Color

lighten(color: ColorInput, amount: number): string

Parameters

NameTypeDescription
colorColorInputAny color Colore accepts: hex, rgb(), hsl(), oklch(), a named color, an object or a Color.
amountnumberA percentage from 0 to 100: how far to move toward white. 0 changes nothing and 100 gives white.

Returns

  • The method returns a new Color. The original is not changed.
  • The function returns a CSS string: hex when the result fits sRGB, color(display-p3 …) or oklch(…) when it is more vivid than sRGB.

Throws

A ColorError when the input is not a valid color, or when amount is outside 0–100. A fraction such as 0.1 also throws, with a hint to pass 10 for 10%.

Lighten a color for hover states

import { colore } from 'colore-js';

const button = colore('#0f766e');

button.lighten(10).hex(); // '#27857c'

For a pale background tint, use mix with white or a palette shade instead: lighten keeps the chroma, so a strong lighten stays vivid.

Lightening a vivid color can push it past what sRGB can show. The method's hex() clips the sRGB channels. The function keeps the wider color in CSS.

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

colore('#7c3aed').lighten(12).hex(); // '#8b4fff'
lighten('#7c3aed', 12);              // 'color(display-p3 0.51406 0.32029 0.97004)'

See Gamut and CSS output for when each format is used.

Lightening in RGB or HSL instead

Two hand-written approaches are common. One adds the same amount to each RGB channel. The other converts to HSL and raises its lightness, which is what tinycolor2 and Sass's lighten() do. Both change the color as well as its lightness. Here is Tailwind's yellow-500, #eab308, with 20 passed to each:

// Add 51 (20% of 255) to each RGB channel
'#ffe63b'

// Add 20 points of HSL lightness, as tinycolor2's lighten(20) does
'#fad45e'

lighten('#eab308', 20); // '#f8c02a'
Start
RGB
HSL
lighten

The RGB version turns greener, with its OKLCH hue moving from 86.0 to 100.5. The HSL version loses some of its color, with chroma dropping from 0.162 to 0.141. lighten keeps hue 85.8 and chroma 0.162.

HSL drains other colors more. On violet-500, #8b5cf6, tinycolor2's lighten(20) keeps only 40% of the chroma, and the result looks washed out. lighten moves 20% of the way to white on every hue and keeps the chroma. The tinycolor2 comparison shows the results for violet, blue and red.