Color Picker

Color Picker

A popover color picker with saturation area, hue and alpha sliders and an eye-dropper. Switches between hex, RGB, HSL and HSB formats.

Playground

label
variant
size
withoutAlpha
<ColorPicker defaultValue="#3b82f6">
  <ColorPickerTrigger>
    <ColorPickerSwatch />
    Pick a color
  </ColorPickerTrigger>
  <ColorPickerContent>
    <ColorPickerArea />
    <ColorPickerHueSlider />
    <ColorPickerAlphaSlider />
    <ColorPickerFormatSelect className="w-full" />
    <ColorPickerInput className="flex-1" />
  </ColorPickerContent>
</ColorPicker>

Preview

Compose the parts inside ColorPicker: ColorPickerTrigger opens the popover, and ColorPickerContent stacks the area, sliders and inputs. ColorPickerSwatch previews the current color anywhere – here inside the trigger.

<ColorPicker defaultValue="#3b82f6">
  <ColorPickerTrigger>
    <ColorPickerSwatch className="size-5" />
    Pick a color
  </ColorPickerTrigger>
  <ColorPickerContent>
    <ColorPickerArea />
    <ColorPickerHueSlider />
    <ColorPickerFormatSelect className="w-full" />
    <ColorPickerInput className="flex-1" />
  </ColorPickerContent>
</ColorPicker>

Installation

npx shadcn@latest add https://espresso-base-ui.vercel.app/r/color-picker.json

Usage

import {
  ColorPicker,
  ColorPickerAlphaSlider,
  ColorPickerArea,
  ColorPickerContent,
  ColorPickerEyeDropper,
  ColorPickerFormatSelect,
  ColorPickerHueSlider,
  ColorPickerInput,
  ColorPickerSwatch,
  ColorPickerTrigger,
} from "@/components/ui/color-picker"
const [color, setColor] = React.useState("#3b82f6")

<ColorPicker value={color} onValueChange={setColor}>
  <ColorPickerTrigger>
    <ColorPickerSwatch className="size-5" />
    {color}
  </ColorPickerTrigger>
  <ColorPickerContent>
    <ColorPickerArea />
    <ColorPickerHueSlider />
    <ColorPickerInput />
  </ColorPickerContent>
</ColorPicker>

Trigger variants and sizes

ColorPickerTrigger maps onto the design system Button: variant picks outline, subtle or ghost, and size spans xs to lg. Pass the matching size to the swatch inside.

<ColorPicker defaultValue="#3b82f6">
  <ColorPickerTrigger variant="subtle" size="sm">
    <ColorPickerSwatch size="sm" />
    #3b82f6
  </ColorPickerTrigger>
  ...
</ColorPicker>

<ColorPicker defaultValue="#10b981">
  <ColorPickerTrigger variant="ghost" size="lg">
    <ColorPickerSwatch size="lg" />
    #10b981
  </ColorPickerTrigger>
  ...
</ColorPicker>

Alpha and eye dropper

Add ColorPickerAlphaSlider for transparency and ColorPickerEyeDropper to sample any pixel on screen – the eye-dropper button renders only in browsers that support the EyeDropper API.

<ColorPicker defaultValue="#ef4444">
  <ColorPickerTrigger>
    <ColorPickerSwatch className="size-5" />
    Pick / Sample
  </ColorPickerTrigger>
  <ColorPickerContent>
    <ColorPickerArea />
    <ColorPickerHueSlider />
    <ColorPickerAlphaSlider />
    <div className="flex items-center gap-2">
      <ColorPickerEyeDropper />
      <ColorPickerFormatSelect className="w-full" />
    </div>
    <ColorPickerInput className="flex-1" />
  </ColorPickerContent>
</ColorPicker>

Inline

The inline prop drops the popover entirely and renders ColorPickerContent as a plain panel – useful for sidebars and settings pages.

<ColorPicker inline defaultValue="#f59e0b">
  <ColorPickerContent className="w-full rounded-lg border bg-popover">
    <ColorPickerArea />
    <ColorPickerHueSlider />
    <ColorPickerAlphaSlider />
    <div className="flex items-center gap-2">
      <ColorPickerSwatch />
      <ColorPickerFormatSelect className="w-full flex-1" />
    </div>
    <ColorPickerInput className="flex-1" />
  </ColorPickerContent>
</ColorPicker>

API reference

ColorPicker holds all state in an external store and shares it with the parts via context. Inside a form it renders a hidden input with the current hex value, so name / required work like a native field. The ColorPickerProps type and a useColorPicker(selector) hook (for reading store state in custom parts) are also exported.

ColorPicker

PropTypeDefaultDescription
valuestring–Controlled color, parsed from hex, rgb(a), hsl(a) or hsb(a) strings.
defaultValuestring"#000000"Initial color when uncontrolled.
onValueChange(value: string) => void–Called with the color serialized in the active format.
format / defaultFormat"hex" | "rgb" | "hsl" | "hsb""hex"Active output format – controlled via format + onFormatChange, or switched in the UI by ColorPickerFormatSelect.
open / defaultOpenbooleanfalsePopover open state; pair the controlled form with onOpenChange.
inlinebooleanfalseRender without a popover – ColorPickerContent becomes a plain div panel.
modalboolean–Forwarded to the underlying Popover.
namestring–Name for the hidden form input (submitted as hex).
disabledbooleanfalseDisables the trigger and every part inside the content.
readOnly / requiredboolean–Forwarded to the hidden form input.
dir"ltr" | "rtl"–Text direction; falls back to the Direction provider.
asChildbooleanfalseMerge the root's props onto the child element.

ColorPickerTrigger

PropTypeDefaultDescription
variant"outline" | "subtle" | "ghost""outline"Visual style, mapped to the corresponding Button variant.
size"xs" | "sm" | "md" | "lg""md"Trigger height, text size and radius.

ColorPickerInput

PropTypeDefaultDescription
withoutAlphabooleanfalseHide the alpha field from the grouped channel inputs.
ComponentDescription
ColorPickerTriggerPopover trigger button (data-slot="color-picker-trigger", plus data-variant and data-size).
ColorPickerContentPanel that stacks the parts (data-slot="color-picker-content"). A PopoverContent normally, a plain div in inline mode.
ColorPickerAreaDraggable saturation/brightness square (data-slot="color-picker-area") with a floating thumb.
ColorPickerHueSliderHue slider, 0–360, over a rainbow track (data-slot="color-picker-hue-slider").
ColorPickerAlphaSliderAlpha slider, 0–100, over a checkerboard track (data-slot="color-picker-alpha-slider").
ColorPickerSwatchLive preview circle (data-slot="color-picker-swatch", role="img" with a spoken color label). Shows a checkerboard behind transparent colors.
ColorPickerEyeDropperScreen-sampling button (data-slot="color-picker-eye-dropper"). Renders only when the browser exposes the EyeDropper API.
ColorPickerFormatSelectTabs that switch the active format between HEX, RGB, HSL and HSB (data-slot="color-picker-format-select").
ColorPickerInputFormat-aware value inputs (data-slot="color-picker-input") – a hex + alpha pair, or grouped channel fields for rgb / hsl / hsb, each with a descriptive aria-label.

Search documentation

Search the component docs