Resolve theme-aware tokens on the server when the server owns the theme and foreground context for a deterministic artifact. Preserve deferred CSS when the browser still owns variables, inheritance, or scheme selection.
Choose an ownership model
| Output | Recommended token form |
|---|---|
| Email, PDF, image, or static export | Concrete resolved colors |
| Browser stylesheet with runtime themes | Deferred CSS expressions |
| Server preview of a known theme | Resolve from an explicit context |
| Shared token source for both | Preserve source expressions and generate each target deliberately |
Deferred expressions compose. The following token selects a theme-specific brand color, then mixes it with currentColor:
use PhpColor\Color\ColorInterface;
use PhpColor\Color\Css\CssColor;
use PhpColor\Color\Css\CssContext;
$brand = CssColor::lightDark(
'var(--brand-light, #1d4ed8)',
'var(--brand-dark, #60a5fa)',
);
$muted = CssColor::mix(
'oklab',
$brand,
CssColor::currentColor(),
0.8,
0.2,
);
$context = CssContext::dark(
['--brand-dark' => '#93c5fd'],
'#f9fafb',
);
$result = CssColor::resolve($muted, $context);
if ($result instanceof ColorInterface) {
echo $result->toCss('srgb');
}
use PhpColor\Color\ColorInterface;
use PhpColor\Color\Css\CssColor;
use PhpColor\Color\Css\CssContext;
$brand = CssColor::lightDark(
'var(--brand-light, #1d4ed8)',
'var(--brand-dark, #60a5fa)',
);
$muted = CssColor::mix(
'oklab',
$brand,
CssColor::currentColor(),
0.8,
0.2,
);
$context = CssContext::dark(
['--brand-dark' => '#93c5fd'],
'#f9fafb',
);
$result = CssColor::resolve($muted, $context);
if ($result instanceof ColorInterface) {
echo $result->toCss('srgb');
}
The output is rgb(168 208 253). The same expression can remain deferred through toCss() when the browser should select the scheme and inherited color later.
Verify tokens as a system
Resolving syntax does not infer semantic roles, generate a complete theme, or guarantee contrast. Keep token names attached, test the pairs used by components, and serialize in the gamut required by each target.
This is server-side resolution, not a browser style engine. The context contains only the values you provide. PHPColor does not read the DOM, cascade, inheritance, media queries, computed styles, or browser support.
Continue with Resolve custom properties, Derive a dark-mode palette, or CssColor.