Skip to content

hslToHex

The hslToHex function converts a color in HSL or HSLA format to hexadecimal format.

Syntax

typescript
hslToHex(hsl: string): string;

Parameters

NameTypeDescription
hslstringColor in HSL or HSLA format

Returns

TypeDescription
stringColor converted to hexadecimal format

Examples

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

Notes

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

References

Released under the MIT License.