OKLCH

Perceptually uniform, hue-first. The working space for design tokens.

Channels
  • L Lightness 0 to 1
  • C Chroma 0 to ~0.4
  • H Hue 0 to 360
CSS syntax
oklch()
White point
D65
Category
Cylindrical
PHP class
OklchColor
Reach for it when
Design tokens, tonal scales, hue manipulation.

Convert to OKLCH in PHP

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

<?php

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

$color->getChannels();
// ['l' => 0.6231, 'c' => 0.188, 'h' => 259.8145]
$color = Color::parse('#3b82f6')->to('oklch'); $color->getChannels(); // ['l' => 0.6231, 'c' => 0.188, 'h' => 259.8145]

Parse OKLCH in PHP

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

<?php

$color = Color::parse('oklch(0.62 0.18 260)');

$color->toHex(); // #3f82f0
$color = Color::parse('oklch(0.62 0.18 260)'); $color->toHex(); // #3f82f0

Export OKLCH in CSS

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

<?php

Color::parse('#3b82f6')->to('oklch')->toCss();
// oklch(0.623083 0.188015 259.815)
Color::parse('#3b82f6')->to('oklch')->toCss(); // oklch(0.623083 0.188015 259.815)

Validate OKLCH

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

<?php

Color::tryFrom('oklch(0.62 0.18 260)'); // instance

Color::tryFrom('oklch(nope)'); // null
Color::tryFrom('oklch(0.62 0.18 260)'); // instance Color::tryFrom('oklch(nope)'); // null