HSL

Familiar hue, saturation, lightness. Not perceptual, still everywhere.

Channels
  • H Hue 0 to 360
  • S Saturation 0% to 100%
  • L Lightness 0% to 100%
CSS syntax
hsl()
White point
D65
Category
Cylindrical
Reach for it when
Reading and writing legacy CSS.

HSL in PHP

HSL is a read-and-write format in PHPColor: parse it from CSS, emit it with toCss(). There is no to('hsl') conversion target.

<?php

Color::parse('#3b82f6')->toCss('hsl');
// hsl(217.219 91.2195% 59.8039%)
Color::parse('#3b82f6')->toCss('hsl'); // hsl(217.219 91.2195% 59.8039%)

Parse HSL in PHP

The regular CSS syntax goes straight into Color::parse().

<?php

$color = Color::parse('hsl(217 91% 60%)');

$color->toHex(); // #3c83f6
$color = Color::parse('hsl(217 91% 60%)'); $color->toHex(); // #3c83f6

Export HSL in CSS

Every color object serializes back to the CSS form of its space.

<?php

Color::parse('#3b82f6')->toCss('hsl');
// hsl(217.219 91.2195% 59.8039%)
Color::parse('#3b82f6')->toCss('hsl'); // hsl(217.219 91.2195% 59.8039%)

Validate HSL

tryFrom() returns null on invalid input instead of throwing.

<?php

Color::tryFrom('hsl(217 91% 60%)'); // instance

Color::tryFrom('hsl(nope)'); // null
Color::tryFrom('hsl(217 91% 60%)'); // instance Color::tryFrom('hsl(nope)'); // null