Skip to content

hexToHsl ​

The hexToHsl function converts a color in hexadecimal format to HSL format.

Syntax ​

typescript
hexToHsl(hex: string): string;

Parameters ​

NameTypeDescription
hexstringColor in hexadecimal format

Returns ​

TypeDescription
stringColor converted to HSL format

Examples ​

typescript
hexToHsl("#ff0000");
// => "hsl(0, 100%, 50%)"

Notes ​

  • Throws an error if the value is not a valid hexadecimal.
  • Useful for conversion between color models.

References ​

Released under the MIT License.