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
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.
Related
- lighten to move toward white, with a comparison of OKLCH, HSL and RGB results
- setOklch to set an exact lightness
- OKLCH in JavaScript for a workflow with both edits