Skip to content
shadcn.io
shadcn.io is not affiliated with official shadcn/ui

Shadcn Color Picker for React and Tailwind

Pick colors with hue and alpha controls.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/color-picker.json

shadcn.io wraps Ark UI Color Picker. value / defaultValue on ColorPicker are strings (parsed with parseColor). useColorPicker takes Ark Color objects — use parseColor("#eb5e41"). Hidden input is baked into ColorPicker / ColorPickerRootProvider. lazyMount and unmountOnExit default to true (Ark: false). positioning.placement defaults to top-start.

useColorPicker is the machine hook for ColorPickerRootProvider. useColorPickerContext / ColorPickerContext is in-tree.

Root Provider

Pass machine options (defaultValue, format, inline, positioning, …) to useColorPicker(), not to the provider. Presence (lazyMount, unmountOnExit) can still be set on the provider.

Context

Open state

Control the popover with open and onOpenChange. { open, value }.

Inline

inline renders area, sliders, and swatches without a popover.

Modes

You can use multiple modes to build the color picker that fits your needs:

  • Input for hex or channel editing
  • Popover for area and slider selection
  • Swatch picker for preset colors
  • Area standalone component for color selection
  • Slider for color adjustment

Input

Anatomy

ColorPicker
├── ColorPickerControl
│   └── InputGroup
│       ├── ColorPickerTrigger
│       │   └── ColorPickerSwatchPreview
│       └── ColorPickerInput
└── ColorPickerContent
    ├── ColorPickerArea
    │   └── ColorPickerAreaThumb
    └── ColorPickerView
        └── ColorPickerSlider

Usage

import {
  ColorPicker,
  ColorPickerInput,
} from "@/components/ui/color-picker";
<ColorPicker>
  <ColorPickerInput asChild channel="hex">
    <Input />
  </ColorPickerInput>
</ColorPicker>

Controlled

Use the value and onValueChange props to programmatically control the color picker's state.

States

Invalid

Disabled

Examples

With Field

Channel Editing

With Swatch

Input with ColorPickerSwatchPreview showing the current color alongside the hex input.

With Popover

An input with trigger and popover content for area, hue, and alpha selection.

Compact

Inspired by Figma's color input.

Popover

Color picker with trigger and popover content.

Anatomy

ColorPicker
├── ColorPickerControl
│   └── ColorPickerTrigger
└── ColorPickerContent
    ├── ColorPickerArea
    │   └── ColorPickerAreaThumb
    ├── ColorPickerView
    │   ├── ColorPickerEyeDropperTrigger
    │   └── ColorPickerSlider
    │       └── ColorPickerTransparencyGrid
    └── ColorPickerSwatchGroup
        └── ColorPickerSwatchTrigger
            └── ColorPickerSwatch

Usage

import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerAreaThumb,
  ColorPickerContent,
  ColorPickerEyeDropperTrigger,
  ColorPickerSlider,
  ColorPickerTrigger,
  ColorPickerTransparencyGrid,
  ColorPickerView,
} from "@/components/ui/color-picker";
<ColorPicker>
  <ColorPickerTrigger />
  <ColorPickerContent>
    <ColorPickerArea>
      <ColorPickerAreaThumb />
    </ColorPickerArea>
    <ColorPickerView>
      <ColorPickerEyeDropperTrigger />
      <ColorPickerSlider channel="hue" />
      <ColorPickerSlider channel="alpha">
        <ColorPickerTransparencyGrid />
      </ColorPickerSlider>
    </ColorPickerView>
  </ColorPickerContent>
</ColorPicker>

States

Disabled

Set disabled to prevent user interaction.

Examples

With Eye Dropper

With Channel Editing

Popover with area, sliders, and input fields for editing red, green, and blue values.

With Only Sliders

Popover with hue, saturation, lightness, and alpha sliders only, no color area.

With Swatch Picker

Popover with preset color swatches for quick selection.

Color Swatch Picker

Set inline on ColorPicker so swatches render without a popover.

Anatomy

ColorPicker
└── ColorPickerSwatchGroup
    └── ColorPickerSwatchTrigger
        └── ColorPickerSwatch
            └── ColorPickerSwatchIndicator

Usage

import {
  ColorPicker,
  ColorPickerSwatchTrigger,
  ColorPickerSwatchGroup,
  ColorPickerSwatch,
  ColorPickerSwatchIndicator,
} from "@/components/ui/color-picker";
<ColorPicker>
  <ColorPickerSwatchGroup>
    <ColorPickerSwatchTrigger value="#0485F7">
      <ColorPickerSwatch value="#0485F7">
          <ColorPickerSwatchIndicator />
      </ColorPickerSwatch>
    </ColorPickerSwatchTrigger>
  </ColorPickerSwatchGroup>
</ColorPicker>

Controlled

Use the value and onValueChange props to programmatically control the swatch picker's state.

States

Disabled

Set disabled to prevent user interaction.

Examples

Custom Size

Customize swatch size using the size-* on ColorPickerSwatchTrigger.

Custom Radius

Override the default rounded style on ColorPickerSwatchTrigger using the rounded-* utility class.

Custom Indicator

Replace the default check icon with a custom indicator via the children of ColorPickerSwatchIndicator.

Area

Set inline on ColorPicker for a standalone color area.

Anatomy

ColorPicker
└── ColorPickerArea
    └── ColorPickerAreaThumb

Usage

import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerAreaThumb,
} from "@/components/ui/color-picker";
<ColorPicker>
  <ColorPickerArea>
    <ColorPickerAreaThumb />
  </ColorPickerArea>
</ColorPicker>

Examples

Color Channels

With Dots

Slider

Set inline on ColorPicker for standalone sliders. Wrap multiple sliders in ColorPickerView.

Anatomy

ColorPicker
└── ColorPickerView
    └── ColorPickerSlider
        └── ColorPickerTransparencyGrid

Usage

import {
  ColorPicker,
  ColorPickerSlider,
} from "@/components/ui/color-picker";
<ColorPicker>
  <ColorPickerSlider channel="hue" />
</ColorPicker>

Controlled

States

Disabled

Examples

Alpha Channel

HSL Channels

HSBA Channels

RGB Channels

Vertical

Custom spacing

Use [--space:--spacing("value")] on ColorPickerContent to adjust internal spacing.

Default spacing is --spacing(3).

You can use breakpoint utilities to change the internal spacing at different screen sizes.

  md:[--space:--spacing(6)] lg:[--space:--spacing(8)]

API Reference

shadcn.io wraps Ark UI Color Picker. Defaults below are shadcn.io values. lazyMount / unmountOnExit default to true (Ark: false). value / defaultValue on ColorPicker are CSS color strings. Ark useColorPicker uses Color from parseColor.

asChild merges props onto a single child element.

ColorPicker

Root. Renders a div. Hidden input is baked in.

PropTypeDefaultDescription
asChildbooleanfalseRender the child element instead of a div.
classNamestring-Class names on the root.
closeOnSelectbooleanfalseClose the popover when a swatch is selected.
defaultFormatColorFormat"rgba"Uncontrolled format.
defaultOpenboolean-Uncontrolled open state.
defaultValuestring"#000000"Uncontrolled color string.
disabledboolean-Disable the picker.
formatColorFormat-Controlled format (hex, hexa, rgb, rgba, hsl, hsla, hsb, hsba, oklch).
hideMode"display-none" | "activity""display-none"How to hide unmounted content. activity needs React 19+.
idstring-Unique id for the machine.
inlinebooleanfalseRender without a popover.
invalidboolean-Invalid state. Also inherited from Field.
lazyMountbooleantrueMount popover content on first open.
namestring-Hidden input name.
onFormatChange(details: FormatChangeDetails) => void-Format changed. { format }.
onOpenChange(details: OpenChangeDetails) => void-Open state changed. { open, value }.
onValueChange(details: ValueChangeDetails) => void-Color changed. { value: Color, valueAsString: string }.
onValueChangeEnd(details: ValueChangeDetails) => void-Color change finished (pointer up).
openboolean-Controlled open state.
positioningPositioningOptions{ placement: "top-start" }Popover position.
readOnlyboolean-Focusable but not editable.
requiredboolean-Required for forms.
unmountOnExitbooleantrueUnmount popover after close animation.
valuestring-Controlled color string.
AttributeDescription
data-slotcolor-picker
data-scopecolor-picker
data-partroot
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only

ColorPickerRootProvider

Takes the API from useColorPicker. Hidden input is baked in.

PropTypeDefaultDescription
valueUseColorPickerReturnrequiredReturn value of useColorPicker().
asChildbooleanfalseRender the child element instead of a div.
classNamestring-Class names on the root.
lazyMountbooleantruePresence: mount content on first open.
unmountOnExitbooleantruePresence: unmount after close.

Pass defaultValue: parseColor("#eb5e41"), format, inline, positioning, and other machine options to useColorPicker(), not to the provider.

ColorPickerLabel

Visible label. Renders a label. Prefer Field for form layouts.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the label.
AttributeDescription
data-slotcolor-picker-label
data-scopecolor-picker
data-partlabel

ColorPickerTrigger

Opens the popover. Renders a button. Use asChild with InputGroupAddon or Button.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the trigger.
AttributeDescription
data-slotcolor-picker-trigger
data-scopecolor-picker
data-parttrigger

ColorPickerContent

Popover surface. Portals with a positioner. Renders a div.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the content. Set [--space:] here.
CSS variableDefaultDescription
--space--spacing(3)Padding and inner gap
AttributeDescription
data-slotcolor-picker-content
data-scopecolor-picker
data-partcontent
data-state"open" or "closed"

ColorPickerControl

Row for input, trigger, and swatch preview. Renders a div.

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the control.

ColorPickerView

Shows children only when its format matches the current format. Renders a div.

PropTypeDefaultDescription
formatColorFormat-Format this view is for.
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the view.

ColorPickerArea

2D selection. Bakes AreaBackground. Renders a div.

PropTypeDefaultDescription
showDotsbooleanfalseshadcn.io: overlay a dotted grid.
xChannel / yChannelColorChannel-Axes for the area.
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the area.

ColorPickerAreaThumb

Thumb on the area. role="slider" with aria-roledescription="2d slider".

PropTypeDefaultDescription
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the thumb.

ColorPickerSlider

Channel slider. Bakes track and thumb. channel is required.

PropTypeDefaultDescription
channelColorChannelrequiredChannel to edit.
orientation"horizontal" | "vertical""horizontal"Slider axis.
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the slider.

ColorPickerTransparencyGrid

Checkerboard for alpha. Place as a child of ColorPickerSlider for the alpha channel.

PropTypeDefaultDescription
sizestring-Grid cell size.
asChildbooleanfalseMerge onto a single child.
classNamestring-Class names on the grid.

ColorPickerEyeDropperTrigger

Always asChild onto Button. Uses the EyeDropper API when the browser supports it. Default aria-label is "Sample color".

PropTypeDefaultDescription
variantButton variant"outline"Button variant.
sizeButton size"icon-md"Button size.
childrenReactNodepipette iconReplace the icon.
classNamestring-Class names on the trigger.

ColorPickerInput

Channel input (ChannelInput). Use asChild with Input or InputGroupInput. Default channel is "hex".

PropTypeDefaultDescription
channelExtendedColorChannel"hex"Channel or "hex" / "css".
asChildbooleanfalseMerge onto a single child.

ColorPickerSwatchPreview

shadcn.io compact current-color swatch (transparency grid + value swatch). Use in an input group addon.

ColorPickerSwatchGroup / ColorPickerSwatchTrigger / ColorPickerSwatch / ColorPickerSwatchIndicator

Preset swatches. ColorPickerSwatchTrigger value is a CSS color string. Indicator defaults to a check icon (aria-hidden).

ColorPickerValue / ColorPickerValueSwatch

Formatted text (ValueText) and current-color swatch (ValueSwatch).

parseColor

Parses a CSS color string into an Ark Color. Required for useColorPicker({ defaultValue }).

parseColor("#eb5e41").toString("hex");

useColorPicker

Creates the API for ColorPickerRootProvider. defaultValue / value are Color, not strings.

const colorPicker = useColorPicker({ defaultValue: parseColor("#eb5e41") });
colorPicker.setValue("#10B981");

ColorPickerContext / useColorPickerContext

Render-prop or hook access. Use inside ColorPicker or ColorPickerRootProvider.

PropertyTypeDescription
valueColorCurrent color object.
valueAsStringstringFormatted color string.
openbooleanWhether the popover is open.
inlinebooleanWhether the picker is inline.
draggingbooleanWhether a thumb is dragging.
formatColorFormatCurrent format.
setValue(value: string | Color) => voidSet the color.
setOpen(open: boolean) => voidOpen or close the popover.
getChannelValue(channel: ColorChannel) => stringChannel as string.
setChannelValue(channel: ColorChannel, value: number) => voidSet one channel.

ColorPickerContext children: (context) => ReactNode.

Accessibility

The area thumb is a 2D slider (aria-roledescription="2d slider"). Channel sliders are sliders with aria-valuetext for the channel. The eye dropper is an icon button (aria-label="Sample color"). Pair inputs with Field. Decorative check and pipette icons are aria-hidden.

Keyboard support

KeyDescription
TabMove between trigger, inputs, area thumb, sliders, swatches, and eye dropper.
Enter / SpaceOpen the popover from the trigger, or select a focused swatch.
EscapeClose the popover. On area/slider, stop propagation so the popover can close.
Arrow keysMove the area thumb (2D) or the focused channel slider. Respects RTL on sliders.
PageUp / PageDownLarger step on the area or slider.
Home / EndMin / max of the focused channel slider.
Shift + ArrowLarger step (native event step multiplier).