Choose a color space

Select a color space according to the operation and output you need.

Choose the space that makes the next operation meaningful, then convert for the consumer that receives the result. For most application work, use Oklch for lightness, chroma, and hue adjustments; Oklab for interpolation; and sRGB or Display P3 for web delivery.

A color space is a coordinate system, not a different color by itself. The same visible color can have different channel values in sRGB, Oklch, Lab, and other spaces because each system describes it with different axes.

Match coordinates to the decision

Task Practical choice Why
Emit broadly usable web colors sRGB It is the standard RGB space used by rgb() and hexadecimal output.
Adjust lightness, chroma, or hue Oklch Its channels correspond directly to those three properties.
Mix colors Oklab Color::mix() uses Oklab by default.
Emit wide-gamut CSS Display P3 It has a wider gamut than sRGB and has native color(display-p3 ...) output.
Compare against CIE-based data Lab, LCH, or CIE XYZ These spaces are intended for colorimetric workflows.
Exchange values with an RGB-specific system Rec. 2020, Adobe RGB, ProPhoto RGB, or linear sRGB The target system, not convenience, should determine the space.
Work with print-like channel data CMYK It exposes cyan, magenta, yellow, and black channels, but does not model a printer profile.

The working space and delivery space do not need to match. A color can enter as sRGB, be adjusted in Oklch, and leave as sRGB plus a Display P3 enhancement.

See one color through several coordinate systems

use PhpColor\Color\Color;

$brand = Color::parse('#3b82f6');

echo $brand->to('oklch')->toCss().PHP_EOL;
echo $brand->to('display-p3')->toCss().PHP_EOL;
echo $brand->toHex().PHP_EOL;
use PhpColor\Color\Color; $brand = Color::parse('#3b82f6'); echo $brand->to('oklch')->toCss().PHP_EOL; echo $brand->to('display-p3')->toCss().PHP_EOL; echo $brand->toHex().PHP_EOL;

The same source produces:

oklch(0.623083 0.188015 259.815)
color(display-p3 0.310018 0.503944 0.936356)
#3b82f6
oklch(0.623083 0.188015 259.815) color(display-p3 0.310018 0.503944 0.936356) #3b82f6

The coordinates differ, but each representation refers to the same source color within conversion precision.

Know where the simple rule stops

Converting into an RGB space does not guarantee that the color lies inside that space's gamut. Formatting as hexadecimal always reduces the value to clamped, eight-bit sRGB. CMYK values are not ICC-managed print output, and Lab-based distance values still require an algorithm and a domain threshold.

PHPColor's high-level lightness, chroma, hue, tint, shade, and default mixing operations already use documented perceptual spaces internally. Convert explicitly when you need to inspect coordinates, exchange a named schema, or control serialization.

Continue with Convert between spaces, Precision and gamut, or Create a seven-step OKLCH scale.