@pbroom/color-kitConversion

toHsl

Convert a Color to HSL (hue in degrees, saturation and lightness 0-100).

functionimport { toHsl } from '@pbroom/color-kit';index.ts:180
function toHsl(color: Color): Hsl;

Computed from the sRGB value clipped to the gamut like toRgb but not rounded to 8-bit, so channels are fractional. Grays get hue and saturation 0.

Parameters

colorColor
Color to convert

Returns

HslA new Hsl

Example

TypeScript
import { parse, toHsl } from '@pbroom/color-kit';

toHsl(parse('#3b82f6')); // → ≈ { h: 217.22, s: 91.22, l: 59.8, alpha: 1 }

See also