Vanilla Breeze

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).
editable boolean Click a swatch to edit its color via the native OS picker. Updates the colors attribute and fires color-palette:change.

Editable mode

Add the editable attribute and each swatch becomes a click-to-edit target. Clicking opens the native OS color picker; changes update the swatch and fire color-palette:change with the full updated colors array.

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 (non-editable mode). The color value is also copied to the clipboard.
color-palette:change { color, name, index, colors } Fired when an editable swatch changes. Includes the full updated colors array.

Accessibility

  • The palette uses role="group" with aria-label="Color palette".
  • Each swatch is a <button> with an aria-label including the color name and value.
  • Full keyboard navigation — Tab between swatches, Enter/Space to copy.