Display P3

The wide gamut of modern screens, Apple displays first.

Channels
  • R Red 0 to 1
  • G Green 0 to 1
  • B Blue 0 to 1
CSS syntax
color(display-p3 ...)
White point
D65
Category
RGB
PHP class
DisplayP3Color
Reach for it when
Vivid UI color on wide-gamut displays.

Convert to Display P3 in PHP

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

<?php

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

$color->getChannels();
// ['r' => 0.31, 'g' => 0.5039, 'b' => 0.9364]
$color = Color::parse('#3b82f6')->to('display-p3'); $color->getChannels(); // ['r' => 0.31, 'g' => 0.5039, 'b' => 0.9364]

Parse Display P3 in PHP

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

<?php

$color = Color::parse('color(display-p3 0.23 0.51 0.96)');

$color->toHex(); // #0984fd
$color = Color::parse('color(display-p3 0.23 0.51 0.96)'); $color->toHex(); // #0984fd

Export Display P3 in CSS

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

<?php

Color::parse('#3b82f6')->to('display-p3')->toCss();
// color(display-p3 0.310018 0.503944 0.936356)
Color::parse('#3b82f6')->to('display-p3')->toCss(); // color(display-p3 0.310018 0.503944 0.936356)

Validate Display P3

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

<?php

Color::tryFrom('color(display-p3 0.23 0.51 0.96)'); // instance

Color::tryFrom('color(nope)'); // null
Color::tryFrom('color(display-p3 0.23 0.51 0.96)'); // instance Color::tryFrom('color(nope)'); // null