Skip to content

hslToRgb

Converts an HSL(A) color into RGB(A).

Available since next

import { hslToRgb } from '@helpers4/color';
hslToRgb(color: HslColor): RgbColor
ParameterTypeDescription
colorHslColorThe color to convert. h is normalized modulo 360 (negative values wrap around), s/l are expected in 0-100, a defaults to 1 (opaque) when omitted.

RgbColor — The equivalent RGB(A) color, with r/g/b rounded to 0-255

Useful after generating a hue programmatically (e.g. evenly spaced chart colors).

hslToRgb({ h: 120, s: 100, l: 50 })
// => { r: 0, g: 255, b: 0, a: 1 }

Negative or out-of-range hues are normalized before conversion.

hslToRgb({ h: -360, s: 100, l: 50 })
// => { r: 255, g: 0, b: 0, a: 1 }  (same as h: 0)

View source on GitHub