color-palette
Interactive color swatch display web component with click-to-copy and multiple layout modes.
Overview
The <color-palette> component renders interactive color swatches from a comma-separated list. Click any swatch to copy its value to the clipboard. Supports hex, rgb, hsl, and oklch color formats.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
colors |
string | — | Comma-separated color values (hex, rgb, oklch, etc.). |
names |
string | — | Comma-separated swatch labels. |
layout |
string | inline |
Display mode: inline, grid, or list. |
show-values |
boolean | — | Show color value text on each swatch. |
show-names |
boolean | — | Show name labels on each swatch. |
size |
string | md |
Swatch size: sm (32px), md (48px), or lg (72px). |
Layout Modes
Grid
Auto-filling grid that wraps responsively.
List
Vertical list with color values alongside.
oklch Colors
The parser handles functional color notation that contains commas, such as oklch().
Events
| Event | Detail | Description |
|---|---|---|
color-palette:select |
{ color, name, index } |
Fired when a swatch is clicked. The color value is also copied to the clipboard. |
Accessibility
- The palette uses
role="group"witharia-label="Color palette". - Each swatch is a
<button>with anaria-labelincluding the color name and value. - Full keyboard navigation — Tab between swatches, Enter/Space to copy.