Derive a dark-mode palette

Transform a named light palette into a dark counterpart while keeping the input keys aligned.

Light palette
PHPColor Keep every role aligned.
Dark palette
PHPColor Keep every role aligned.
background
#f8fafc#0b0c0e
text
#0f172a#c0cde7
accent
#2563eb#4f88fc
border
#cbd5e1#0d141c

Transform every named color together

The returned palette keeps the source keys and order, so light and dark values remain aligned under the names assigned by your application.

Apply one perceptual formula

DarkModeColorPaletteTransformer adjusts lightness and chroma across the complete palette and returns new color objects.

<?php

use PhpColor\Color\Palette\ColorPalette;
use PhpColor\Color\Palette\Transformer\DarkModeColorPaletteTransformer;

$light = ColorPalette::parse([
    'background' => '#f8fafc',
    'text' => '#0f172a',
    'accent' => '#2563eb',
    'border' => '#cbd5e1',
]);

$dark = (new DarkModeColorPaletteTransformer())->transform($light);

print_r($dark->toHex());
use PhpColor\Color\Palette\ColorPalette; use PhpColor\Color\Palette\Transformer\DarkModeColorPaletteTransformer; $light = ColorPalette::parse([ 'background' => '#f8fafc', 'text' => '#0f172a', 'accent' => '#2563eb', 'border' => '#cbd5e1', ]); $dark = (new DarkModeColorPaletteTransformer())->transform($light); print_r($dark->toHex());

Keep the same application names

Each transformed value retains its source color-space type and alpha. The intended OKLCH hue is preserved before conversion back to that type.

Array
(
    [background] => #0b0c0e
    [text] => #c0cde7
    [accent] => #4f88fc
    [border] => #0d141c
)

Review the result as a theme

The transformation provides a coherent starting point. Check the actual foreground and background pairs after serialization.

Roles come from your application

The transformer does not understand what background, text, accent, or border means.

Contrast still needs verification

One fixed formula does not guarantee pairwise contrast or an accessible dark theme.

Build both themes

Transform the palette, then verify its real color pairs