Build color harmonies

Derive geometric hue relationships from one source color.

Choose a harmony when a palette needs an explicit geometric hue relationship. Use it as a starting structure, then decide lightness, chroma, semantic roles, gamut, and contrast separately.

Choose geometry from the number of roles

Relationship Useful starting point Main risk
Complementary Two opposing roles Visual competition
Analogous Related surfaces or categories Insufficient separation
Split complementary One anchor plus two softer opponents Uneven prominence
Triadic Three distinct families Contrast and hierarchy still vary
Tetradic Four families or paired opposites Too many equal accents

Harmony methods belong to color objects rather than ColorPalette. They rotate hue in Oklch and return colors in the same concrete space as the source.

Generate the selected relationship

use PhpColor\Color\Color;
use PhpColor\Color\Palette\ColorPalette;

$base = Color::parse('#3b82f6');
$harmony = ColorPalette::scale($base->triadic());

foreach ($harmony as $color) {
    echo $color->toHex();
}
use PhpColor\Color\Color; use PhpColor\Color\Palette\ColorPalette; $base = Color::parse('#3b82f6'); $harmony = ColorPalette::scale($base->triadic()); foreach ($harmony as $color) { echo $color->toHex(); }

Available methods are:

Method Returned colors
complementary() One color rotated by 180 degrees
analogous() The source, then colors alternating by +30 and -30 degrees
splitComplementary() The source, +150 degrees, and +210 degrees
triadic() The source, +120 degrees, and +240 degrees
tetradic() The source, +90, +180, and +270 degrees

analogous(int $count = 2) returns the source plus the requested number of neighbors. A count below one returns an empty array:

use PhpColor\Color\Color;

$five = Color::parse('#3b82f6')->analogous(4);

echo count($five);
use PhpColor\Color\Color; $five = Color::parse('#3b82f6')->analogous(4); echo count($five);

The output is 5.

Verify the roles after generation

These methods encode geometric hue relationships, not a guarantee of accessible contrast, in-gamut output, or equal visual prominence. Validate generated colors for the target gamut and use Contrast and accessibility for foreground/background decisions.

Use harmony detection to describe an existing palette and harmony repair to realign one; neither replaces semantic review. Continue with Detect a palette harmony, Repair a triadic palette, or Generate color harmonies.