Color Picker
A composable color picker built on Radix primitives, supporting HEX, RGB, HSL, and HSB formats with optional alpha transparency. It provides a popover or inline layout, saturation/value selection, hue and alpha sliders, format-specific inputs, an eyedropper, swatches, and native form integration.
ui · no preview
This item cannot be built as published, so there is no live preview: install:
See how it was built Installation
pnpm dlx shadcn@latest add https://diceui.com/r/radix-vega/color-picker.json
Usage
usage.tsx
import { ColorPicker, ColorPickerArea, ColorPickerAlphaSlider, ColorPickerContent, ColorPickerFormatSelect, ColorPickerHueSlider, ColorPickerInput, ColorPickerSwatch, ColorPickerTrigger,} from "@/components/ui/color-picker";export function Example() { return ( <ColorPicker defaultValue="#7c3aed" name="accent-color"> <ColorPickerTrigger aria-label="Choose accent color"> <ColorPickerSwatch /> </ColorPickerTrigger> <ColorPickerContent> <ColorPickerArea /> <ColorPickerHueSlider aria-label="Hue" /> <ColorPickerAlphaSlider aria-label="Opacity" /> <div className="flex items-center gap-2"> <ColorPickerFormatSelect aria-label="Color format" /> <ColorPickerInput className="flex-1" /> </div> </ColorPickerContent> </ColorPicker> );}- Let users choose colors for themes, branding, illustrations, charts, or design tokens.
- Use the popover composition when space is limited and the picker should open from a trigger swatch or button.
- Use inline mode when the color controls should remain permanently visible in an editor or settings panel.
- Use the format selector and inputs when users need precise color or alpha values in addition to visual picking.
Examples
Inline picker
Keeps the complete picker visible without a popover.
inline-picker.tsx
import { ColorPicker, ColorPickerAlphaSlider, ColorPickerArea, ColorPickerContent, ColorPickerHueSlider, ColorPickerInput,} from "@/components/ui/color-picker";export function InlineColorPicker() { return ( <ColorPicker inline defaultValue="#0ea5e9"> <ColorPickerContent> <ColorPickerArea /> <ColorPickerHueSlider aria-label="Hue" /> <ColorPickerAlphaSlider aria-label="Opacity" /> <ColorPickerInput withoutAlpha /> </ColorPickerContent> </ColorPicker> );}Controlled color value
Controls the serialized color value from application state.
controlled-color-value.tsx
import * as React from "react";import { ColorPicker, ColorPickerArea, ColorPickerContent, ColorPickerHueSlider, ColorPickerSwatch, ColorPickerTrigger,} from "@/components/ui/color-picker";export function ControlledColorPicker() { const [color, setColor] = React.useState("rgba(59, 130, 246, 0.8)"); return ( <ColorPicker value={color} onValueChange={setColor}> <ColorPickerTrigger aria-label="Choose background color"> <ColorPickerSwatch /> </ColorPickerTrigger> <ColorPickerContent> <ColorPickerArea /> <ColorPickerHueSlider aria-label="Hue" /> </ColorPickerContent> </ColorPicker> );}Precise format editing
Starts in HSL mode and exposes numeric channel inputs with alpha.
precise-format-editing.tsx
import { ColorPicker, ColorPickerContent, ColorPickerFormatSelect, ColorPickerInput,} from "@/components/ui/color-picker";export function HslColorField() { return ( <ColorPicker defaultValue="#f97316" defaultFormat="hsl" inline> <ColorPickerContent> <div className="flex items-center gap-2"> <ColorPickerFormatSelect /> <ColorPickerInput /> </div> </ColorPickerContent> </ColorPicker> );}API reference
PropTypeDefaultDescription
ColorPickerColorPickerPropsnullRoot color-picker state provider. Extends div props except onValueChange and accepts Popover defaultOpen, open, onOpenChange, and modal props. Explicit props: value?: string; defaultValue?: string (defaults to #000000); onValueChange?: (value: string) => void; dir?: "ltr" | "rtl"; format?: "hex" | "rgb" | "hsl" | "hsb"; defaultFormat?: "hex" | "rgb" | "hsl" | "hsb" (defaults to hex); onFormatChange?: (format: ColorFormat) => void; name?: string; asChild?: boolean; disabled?: boolean; inline?: boolean; readOnly?: boolean; required?: boolean.
ColorPickerTriggerReact.ComponentProps<typeof PopoverTrigger>nullPopover trigger. Inherits PopoverTrigger props, including asChild and disabled. The root disabled state is combined with the trigger disabled state.
ColorPickerContentReact.ComponentProps<typeof PopoverContent>nullPicker panel. Inherits PopoverContent props and supports asChild. In inline mode it renders the equivalent content container without Popover behavior.
ColorPickerAreaDivPropsnullSaturation/value selection area. Extends div props with asChild?: boolean. Pointer interaction updates saturation and value; pointer event handlers are supported.
ColorPickerHueSliderReact.ComponentProps<typeof SliderPrimitive.Root>nullHue slider based on Radix Slider.Root. Inherits slider root props, but its value is controlled internally from hue state, with max fixed to 360 and step fixed to 1.
ColorPickerAlphaSliderReact.ComponentProps<typeof SliderPrimitive.Root>nullAlpha slider based on Radix Slider.Root. Inherits slider root props, but its value is controlled internally from alpha state, with max fixed to 100 and step fixed to 1.
ColorPickerSwatchDivPropsnullColor preview swatch. Extends div props with asChild?: boolean. Renders role=img and an automatically generated aria-label describing the current color.
ColorPickerEyeDropperReact.ComponentProps<typeof Button>nullButton for the browser EyeDropper API. Inherits Button props; children are optional, size defaults to icon when there are no children and default otherwise. Renders null when EyeDropper is unavailable.
ColorPickerFormatSelectColorPickerFormatSelectPropsnullFormat selector. Extends Select props except value and onValueChange, plus SelectTrigger size and className. Supported values are hex, rgb, hsl, and hsb; the select is controlled by the picker store.
ColorPickerInputColorPickerInputPropsnullFormat-specific color input. Extends Input props except value, onChange, and color, and adds withoutAlpha?: boolean. Renders HEX, RGB, HSL, or HSB numeric/text fields according to the active format.
useColorPicker(selector: (state: StoreState) => U) => UnullExported alias of the internal store hook. Selects a value from the internal store state, whose fields are color, hsv, open, and format. It must be used within ColorPicker.
Accessibility
- The root can create a visually hidden native input using name, value, disabled, readOnly, and required, allowing form submission and native form semantics.
- ColorPickerSwatch uses role="img" with an aria-label such as “Current color: #7c3aed” or “No color selected.”
- The hue and alpha controls use Radix Slider primitives and support keyboard slider interaction; provide meaningful aria-label values when their surrounding UI does not label them.
- ColorPickerInput supplies explicit aria-label values for color channels and alpha percentage fields.
- The trigger, format select, and eyedropper inherit the accessibility behavior of the underlying Button, Popover, Select, and input components.
- The saturation/value area is pointer-oriented and does not add a built-in keyboard or ARIA slider role; provide an accessible label and consider an additional textual input for keyboard users.
- The eyedropper is omitted when the browser does not expose window.EyeDropper, so a text-input or slider-based fallback should remain available.
Docs written by openai:gpt-5.6-luna from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
prompt.md
Use the "Color Picker" component (diceui-radix/color-picker) from its shadcn registry.1. Install it with: npx shadcn@latest add https://diceui.com/r/radix-vega/color-picker.json2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: ColorPicker, ColorPickerTrigger, ColorPickerContent, ColorPickerArea, ColorPickerHueSlider, ColorPickerAlphaSlider, ColorPickerSwatch, ColorPickerEyeDropper, ColorPickerFormatSelect, ColorPickerInput, useColorPicker.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ColorPicker, ColorPickerArea, ColorPickerAlphaSlider, ColorPickerContent, ColorPickerFormatSelect, ColorPickerHueSlider, ColorPickerInput, ColorPickerSwatch, ColorPickerTrigger,} from "@/components/ui/color-picker";export function Example() { return ( <ColorPicker defaultValue="#7c3aed" name="accent-color"> <ColorPickerTrigger aria-label="Choose accent color"> <ColorPickerSwatch /> </ColorPickerTrigger> <ColorPickerContent> <ColorPickerArea /> <ColorPickerHueSlider aria-label="Hue" /> <ColorPickerAlphaSlider aria-label="Opacity" /> <div className="flex items-center gap-2"> <ColorPickerFormatSelect aria-label="Color format" /> <ColorPickerInput className="flex-1" /> </div> </ColorPickerContent> </ColorPicker> );}```Files & dependencies
- ui/color-picker.tsx
- components/visually-hidden-input.tsx
- lib/compose-refs.ts
dependenciescnradix-ui
registryDependenciesbuttoninputpopoverselect@diceui/use-as-ref@diceui/use-isomorphic-layout-effect@diceui/use-lazy-ref
Looks similar, elsewhere
There is no screenshot of this item to compare yet.