HWB

A pure hue plus whiteness and blackness: the human way to mix a tint.

Channels
  • H Hue 0 to 360
  • W Whiteness 0% to 100%
  • B Blackness 0% to 100%
CSS syntax
hwb()
White point
D65
Category
Cylindrical
PHP class
HwbColor
Reach for it when
Tint-and-shade picking, CSS Color 4 output.

Convert to HWB in PHP

Any color converts with to(); the result is HWB, an object with its own channels.

<?php

$color = Color::parse('#3b82f6')->to('hwb');

$color->getChannels();
// ['h' => 217.2193, 'w' => 0.2314, 'b' => 0.0353]
$color = Color::parse('#3b82f6')->to('hwb'); $color->getChannels(); // ['h' => 217.2193, 'w' => 0.2314, 'b' => 0.0353]

Parse HWB in PHP

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

<?php

$color = Color::parse('hwb(217 23% 4%)');

$color->toHex(); // #3b82f5
$color = Color::parse('hwb(217 23% 4%)'); $color->toHex(); // #3b82f5

Export HWB in CSS

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

<?php

Color::parse('#3b82f6')->to('hwb')->toCss();
// hwb(217.219 23.1373% 3.52941%)
Color::parse('#3b82f6')->to('hwb')->toCss(); // hwb(217.219 23.1373% 3.52941%)

Validate HWB

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

<?php

Color::tryFrom('hwb(217 23% 4%)'); // instance

Color::tryFrom('hwb(nope)'); // null
Color::tryFrom('hwb(217 23% 4%)'); // instance Color::tryFrom('hwb(nope)'); // null