palette-generator
Generate harmonious color palettes from a seed color. Extends color-palette with algorithmic palette generation for design systems.
Overview
The <palette-generator> component generates harmonious color palettes from a single seed color. It extends <color-palette>, inheriting all swatch rendering, click-to-copy, and layout features while adding algorithmic palette generation.
<palette-generator seed="#6366f1" harmony="triadic" show-values show-names></palette-generator>
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
seed |
string | — | Hex seed color (e.g. #6366f1). Overridden by child input if present. |
harmony |
string | complementary |
Algorithm: complementary, analogous, triadic, split-complementary, tetradic, monochromatic. |
include-seed |
boolean | true | Whether the seed color appears in the palette. |
show-export |
boolean | — | Show Copy Hex / Copy CSS export toolbar below the palette. |
layout |
string | inline |
Inherited from color-palette: inline, grid, or list. |
size |
string | md |
Inherited swatch size: sm, md, or lg. |
show-values |
boolean | — | Inherited: always show hex values on swatches. |
show-names |
boolean | — | Inherited: show name labels below swatches. |
Harmony Types
Complementary
Two colors opposite on the color wheel (+180°). High contrast, bold combinations.
<palette-generator seed="#e74c3c" harmony="complementary" show-values show-names size="lg"></palette-generator>
Analogous
Three adjacent hues at ±30°. Harmonious, low-contrast palettes.
<palette-generator seed="#3498db" harmony="analogous" show-values show-names size="lg"></palette-generator>
Triadic
Three hues evenly spaced at 120°. Vibrant, balanced palettes.
<palette-generator seed="#2ecc71" harmony="triadic" show-values show-names size="lg"></palette-generator>
Split-Complementary
Seed plus two hues flanking the complement at ±30°. Softer than complementary.
<palette-generator seed="#9b59b6" harmony="split-complementary" show-values show-names size="lg"></palette-generator>
Tetradic
Four hues evenly spaced at 90°. Rich palettes with many accent options.
<palette-generator seed="#f39c12" harmony="tetradic" show-values show-names size="lg"></palette-generator>
Monochromatic
An 11-step lightness ramp matching the 50–950 design token scale. Ideal for generating custom color token sets.
<palette-generator seed="#6366f1" harmony="monochromatic" show-values show-names layout="grid"></palette-generator>
Interactive Mode
Place a <color-picker> or <input type="color"> inside the component to enable live seed selection. The palette regenerates as you pick colors.
<palette-generator harmony="analogous" show-values show-names show-export> <color-picker> <input type="color" value="#6366f1" /> </color-picker></palette-generator>
Also works with a plain native color input:
<palette-generator harmony="triadic" show-values> <input type="color" value="#e74c3c" /></palette-generator>
Export
Add show-export to display a toolbar with two copy buttons below the palette:
- Copy Hex — comma-separated hex list
- Copy CSS — CSS custom properties, e.g.
--palette-base: #6366f1;
For monochromatic palettes, CSS export uses token-style names: --color-seed-50 through --color-seed-950.
<palette-generator seed="#e74c3c" harmony="triadic" show-values show-names show-export></palette-generator>
Events
| Event | Detail | Description |
|---|---|---|
palette-generator:generate |
{ colors, harmony, seed } |
Fired when a palette is computed or regenerated. |
color-palette:select |
{ color, name, index } |
Inherited. Fired when a swatch is clicked (also copies to clipboard). |
document.querySelector('palette-generator') .addEventListener('palette-generator:generate', (e) => { console.log(e.detail); // { colors: ['#6366f1', '#f16366', '#66f163'], harmony: 'triadic', seed: '#6366f1' } });
Accessibility
- Inherits all
<color-palette>accessibility features:role="group", swatch buttons witharia-label, full keyboard navigation. - The export toolbar uses
role="toolbar"witharia-label="Export palette". - Copy feedback is communicated via button text change (visible to screen readers).