Color picker
A button that shows a colour and opens a picker with saturation/brightness, hue and opacity sliders, hex/RGB/HSL input, and swatches. Use ColorPickerPanel directly for sidebars or settings.
Install
npx shadcn@latest add @thrum-pro/color-pickerThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | The colour as hex, when the parent holds it: #rrggbb, or #rrggbbaa when it is not fully opaque. Any format the field reads is accepted. |
defaultValue | string | Default "#2563eb" | The colour at first, when the picker holds it itself. |
onValueChange | (value: string) => void | – | Called with the new colour as lower-case hex while the reader drags, types or picks. |
alpha | boolean | Default false | Add an opacity slider, and opacity in the field. Without it every colour is opaque. |
swatches | readonly string[] | – | Colours to pick with one press. The one that matches the colour is shown pressed. |
defaultFormat | "hex" | "rgb" | "hsl" | Default "hex" | The format the text field starts in. The reader can switch it. |
disabled | boolean | Default false | Dimmed, and nothing can be changed. The button does not open. |
ColorPicker: aria-label | string | Default "Colour" | What the colour is for. It names the button, before the hex value, and the panel. |
ColorPicker: name | string | – | The form field name. A hidden input carries the hex value. |
ColorPicker: side | "top" | "right" | "bottom" | "left" | Default "bottom" | The side of the button the panel opens on. It flips when there is no room. |
ColorPicker: align | "start" | "center" | "end" | Default "start" | How the panel lines up with the button. |
ColorPicker: sound | boolean | Default true | Play the popover's soft sounds when it opens and closes and a click on swatch picks, if the visitor has sound on. |
ColorPicker: triggerClassName | string | – | Classes for the button. |
ColorPickerPanel: surface | boolean | Default true | Paint the panel's own rounded border and glass surface. Set to false when embedded inside another panel. |
className | string | – | ColorPickerPanel: classes for the panel, such as its width. It fills its container. |
Motion and sound
Motion
- The panel fades in and grows from 96% to full size over 150 ms, from the edge that touches the button, and plays it backwards to close.
- Swatches scale subtly to 110% on hover and 95% on press over 150 ms. The marks follow the pointer and the keys with no easing, so they stay under the finger.
- Reduced motion: the panel appears and leaves at once and swatches do not scale.
Sound
- A soft rising tone when the panel opens, a falling one when it closes, and a soft click when a swatch is picked. Dragging and typing are silent.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- The area is hand-built on the WAI-ARIA slider pattern, in two dimensions: role slider named Saturation and brightness, with a value text that names the colour, such as dark blue, #1e3a8a, saturation 80%, brightness 54%.
- Hue and opacity are Base UI sliders over native range inputs, named Hue and Opacity, with the hue's colour name in their value text.
- The button is named by aria-label and the hex value, as in Brand colour: #2563eb. The panel is a non-modal dialog with the same name.
- Swatches are toggle buttons named by colour and hex; the current one is pressed and outlined, not only coloured.
- A colour typed in a format the field cannot read marks the field invalid and says what it expects.
- Under a glass material the panel is translucent. Its tint keeps the text at 4.5 to 1 over any page; the colour ramps stay solid.
| Keys | Action |
|---|---|
| Enter / Space | On the button: open the panel. The focus moves to the area. |
| ← / → | Area: less or more saturation. Sliders: less or more hue or opacity. |
| ↑ / ↓ | Area: brighter or darker. Sliders: more or less. |
| Shift + arrow | Move 10 steps at a time. |
| Page Up / Page Down | Area: 10 steps brighter or darker. Sliders: 10 steps. |
| Home / End | Area: no saturation or full saturation. Sliders: the lowest or highest value. |
| Enter | In the text field: apply the typed colour. |
| Esc | In the text field with an edit: drop the edit. Otherwise close the panel; the focus returns to the button. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/color-picker.tsx- Packages
@base-ui/react@1.9.0- Brings along
- ButtonInputNative selectPopoverSound engine
Changelog
- 1.0.0 · 2026-12-03First release.