Schemelight
--surface: #f8fafcResolved#f8fafc
SrgbColorUse one deferred expression and an explicit scheme to select its concrete color.
light-dark(var(--surface), rgb(11 12 14))
--surface: #f8fafcSrgbColorSrgbColorThe expression stays the same. A light context selects #f8fafc; a dark context selects #0b0c0e. Without a scheme, the expression remains deferred.
Each branch may be a concrete color or another resolvable expression. Here the light branch reads --surface from the context.
<?php
use PhpColor\Color\Css\CssColor;
use PhpColor\Color\Css\CssContext;
$expression = CssColor::lightDark(
CssColor::var('--surface'),
'#0b0c0e',
);
$light = CssContext::light(['--surface' => '#f8fafc']);
$dark = CssContext::dark(['--surface' => '#f8fafc']);
echo CssColor::resolve($expression, $light)->toHex(); // #f8fafc
echo CssColor::resolve($expression, $dark)->toHex(); // #0b0c0e
use PhpColor\Color\Css\CssColor;
use PhpColor\Color\Css\CssContext;
$expression = CssColor::lightDark(
CssColor::var('--surface'),
'#0b0c0e',
);
$light = CssContext::light(['--surface' => '#f8fafc']);
$dark = CssContext::dark(['--surface' => '#f8fafc']);
echo CssColor::resolve($expression, $light)->toHex(); // #f8fafc
echo CssColor::resolve($expression, $dark)->toHex(); // #0b0c0e
light-dark() selects between two supplied expressions. It does not derive a palette or decide which scheme is active.
PHPColor does not inspect browser preferences, evaluate media queries, or perform browser support checks.
PHPColor resolves what it can inside both branches and retains light-dark(rgb(248 250 252), rgb(11 12 14)), even in strict mode.