Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Color Picker for Radix UI

A color picker for React and Radix UI projects: a hex field with a swatch, and a popover with a color area, hue and opacity sliders and presets.

On this page9 sections

Radix UI does not include this primitive, so this page uses the Ark UI component. The visuals match the Ark UI version.

A color picker holds one color. People drag across a color area and channel sliders to find it or type in a known hex code, and a row of preset swatches covers a fixed palette. The parts compose into a hex field with a popover, an always-open panel or a row of brand colors. It runs on Ark UI's color picker on every base, so its props are Ark UI's.

If people only paste hex codes and never need to see the color, a plain Input is enough.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Color Picker anatomy: trigger, input, area, area thumb, eye dropper trigger, slider, content

Usage

import {
  ColorPicker, ColorPickerArea, ColorPickerAreaThumb,
  ColorPickerContent, ColorPickerControl, ColorPickerInput,
  ColorPickerSlider, ColorPickerSwatchPreview,
  ColorPickerTransparencyGrid, ColorPickerTrigger, ColorPickerView,
} from "@/components/ui/color-picker";
import {
  InputGroup, InputGroupAddon, InputGroupInput,
} from "@/components/ui/input-group";

The trigger is a plain button inside the addon, so it takes focus and opens the popover with Enter or Space. format is hsla on both ColorPicker and ColorPickerView, because a view renders only in the picker's format and the hue slider's keys need a format that has hue.

<ColorPicker className="w-full max-w-64" defaultValue="#eb5e41" format="hsla">
  <ColorPickerControl>
    <InputGroup>
      <InputGroupAddon>
        <ColorPickerTrigger className="rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring">
          <ColorPickerSwatchPreview />
        </ColorPickerTrigger>
      </InputGroupAddon>
      <ColorPickerInput asChild>
        <InputGroupInput aria-label="Brand color" />
      </ColorPickerInput>
    </InputGroup>
  </ColorPickerControl>
  <ColorPickerContent>
    <ColorPickerArea>
      <ColorPickerAreaThumb />
    </ColorPickerArea>
    <ColorPickerView format="hsla">
      <ColorPickerSlider channel="hue" />
      <ColorPickerSlider channel="alpha">
        <ColorPickerTransparencyGrid />
      </ColorPickerSlider>
    </ColorPickerView>
  </ColorPickerContent>
</ColorPicker>

Accessibility

The popover is a dialog. Opening it moves focus to its first control, and Escape closes it and puts focus back on the trigger. The area's thumb is a two-dimensional slider, each channel slider has a plain one, and both read out their channel values. Ark UI's names for the parts are generic English: a channel input is called hex or red by an aria-label that outranks any <label>, so pass ColorPickerInput an aria-label matching its visible label, as With field does. A swatch is named by its color, and the selected one is marked with aria-pressed. Keep ColorPickerTrigger a button inside the addon, as Usage does: with asChild on InputGroupAddon it lands on a div the keyboard can't reach.

Enter
When focus is on the trigger, opens the color picker. When focus is on a trigger of a swatch, selects the color (and closes the color picker when closeOnSelect is set). When focus is on the input or channel inputs, selects the color.
Arrow Left
When focus is on the color area, decreases its horizontal channel, saturation unless xChannel sets another. When focus is on the channel sliders, decreases the value of the channel.
Arrow Right
When focus is on the color area, increases its horizontal channel, saturation unless xChannel sets another. When focus is on the channel sliders, increases the value of the channel.
Arrow Up
When focus is on the color area, increases its vertical channel, brightness (lightness with an hsla format) unless yChannel sets another. When focus is on the channel sliders, increases the value of the channel.
Arrow Down
When focus is on the color area, decreases its vertical channel, brightness (lightness with an hsla format) unless yChannel sets another. When focus is on the channel sliders, decreases the value of the channel.
Escape
Closes the color picker and moves focus to the trigger.
Space
When focus is on the trigger, a swatch or the eyedropper button, presses it, as Enter does.
Page Up
When focus is on the color area, increases its horizontal channel by 10, as Shift + ArrowRight does.
Page Down
When focus is on the color area, decreases its horizontal channel by 10, as Shift + ArrowLeft does.
Home
When focus is on a channel slider, sets that channel to its minimum.
End
When focus is on a channel slider, sets that channel to its maximum.

Demos

Area channels

An inline area with xChannel set to hue and yChannel set to alpha, starting from a deep blue, so one drag picks the color family and its opacity together. Reach for it in a highlighter or an overlay tool where those are the only two choices. Without the two props, this area would map saturation across and brightness up.

Preview width

Area dots

The same hue and opacity area, starting from green, with showDots laying a grid of dots 8 pixels apart over it. The dots are drawn on top and don't snap the thumb. They give the eye fixed points to come back to when someone matches a color against a reference by eye.

Preview width

Context

ColorPickerContext hands the picker's state to what it renders, and here a caption above the hex input prints valueAsString. It reads rgba(235, 94, 65, 1) until a new hex is committed with Enter or by leaving the field. Use it for a caption or a preview beside the field when you don't need the color in your own state.

Preview width

Custom spacing

The default popover, with padding and gap classes on ColorPickerContent that set both to 8 pixels on a phone and 16 from the sm breakpoint up, where the default is 12. Classes you pass merge over the content's own through cn, so the last one wins. Tighten the popover on small screens, or give it room on a desktop.

Preview width

Inline

With inline, the picker drops the trigger and the popover and keeps the color area on the page, with four preset swatches under it in blue, red, amber and green. A click on a swatch sets the color and shows a check on it. Use it in a theme editor or a sidebar that is already open, where a popover would cover the preview people are judging.

Preview width

Input channel

Four separate pickers, one per row: red, green and blue, then hue, saturation and brightness, then hue, saturation and lightness, then a hex code with an alpha field. Each number is a ColorPickerInput with its own channel, and a typed value applies on Enter or when focus leaves. Use number fields when people copy exact values out of a design tool.

Preview width

Input compact

One row holds the swatch that opens the popover, a hex field and an opacity field, split by a Separator. The popover adds a dotted area and sliders for hue, saturation, lightness and alpha. The opacity field shows alpha as Ark UI stores it, from 0 to 1, so convert it yourself if people think in percent. Use the layout where the resting control has to stay one line tall.

Preview width

Input controlled

The color lives in state and goes back in as value after every change, stored as the picker's valueAsString. That arrives as an rgba() string because no format is set, so the line below runs it through parseColor to print hex. Control the picker when the color is saved elsewhere or another control on the page also changes it.

Preview width

Input disabled

disabled on ColorPicker reaches the hex input, which shows the current color but can't be focused or edited. Use it when the color comes from a parent theme or workspace and this screen only displays it. If the setting doesn't apply here at all, leave the field out rather than show a locked one.

Preview width

Input invalid

The picker sits in a Field marked invalid, starting on a pale yellow, with a FieldError that says it is too light to read on white. The picker never holds a color it can't parse, since a bad entry snaps back to the last good one on Enter or blur. Set invalid from a rule of your own, such as this contrast check or a server response.

Preview width

Input with popover

The swatch in the input group opens a popover with the color area and a single hue slider: no opacity, no eyedropper. Use this shorter version when colors are always opaque, such as a tag or a calendar color, and most people type or paste a hex anyway. The area and the slider are there for the ones who browse.

Preview width

Input with swatch preview

Here the swatch only shows the color. It sits in an InputGroupAddon with no trigger around it, so nothing opens, typing is the whole interaction, and a click on the swatch moves focus to the input. Use it for a brand hex pasted from a style guide, where the swatch confirms the paste.

Preview width

Open controlled

A button above the field sets open in state to show the popover, and every open and close from the swatch, Escape or a click outside is written back to that state. Drive open yourself when a toolbar action or a shortcut should reveal the panel. The picker's onInteractOutside handler ignores presses on that button, so its own click closes an open popover rather than reopening it.

Preview width

Popover disabled

disabled on ColorPicker disables the trigger, a ghost button with a swatch and a label, so the popover never opens while the current color stays in view. Use it while a permission or a lock stops someone from changing a color they still need to see. Hide the control from someone who will never be allowed to pick.

Preview width

Popover sliders only

The trigger opens four labeled sliders for hue, saturation, lightness and alpha, with no color area, and the alpha track sits over the checkerboard. Use separate sliders when people change one property at a time, such as darkening a brand color without shifting its hue. For a first pick from nothing, the area gets there faster.

Preview width

Popover with channel editing

The popover pairs the area and a hue slider with number fields for hue, saturation and lightness, starting on black with no defaultValue. Its format is hsla: with rgba and fields for red, green and blue, the hue slider's keys would fail, as the FAQ explains. Offer both when some people drag and others type values they measured in a design tool.

Preview width

Popover with swatch picker

The popover holds the area, a hue slider and a row of nine preset swatches, each a 16 pixel square with a ring on the selected one. A click on a swatch sets the color and leaves the popover open. Use the mix for a brand palette that still lets people reach any other color.

Preview width

Root provider

useColorPicker creates the picker's state outside the tree, and ColorPickerRootProvider hands it to the parts. The caption reads valueAsString from it, and Reset calls setValue with the starting hex. The hook takes a parsed color, so its defaultValue goes through parseColor. Use it when code outside the picker has to change the color, not only read it.

Preview width

Slider alpha channel

One inline slider for alpha, with ColorPickerTransparencyGrid inside so the checkerboard shows through the track, starting from red at half opacity. format is rgba, so the opacity lands in the value as its fourth number. Put it under a swatch when the hue is settled and only the strength of a highlight or an overlay is left.

Preview width

Slider controlled

A controlled hue slider with its value string printed under it. The state starts as an rgba() string, but the picker's format is hsla, so the first drag turns the line into an hsla() string. Control a slider like this when something else on the page, such as a live preview, needs every change as it happens.

Preview width

Slider disabled

disabled on an inline picker fades the hue slider to half opacity and takes its thumb out of the tab order, so neither the pointer nor the keyboard moves it. Use it when the hue comes from somewhere else, such as a theme already chosen, and the slider explains the color rather than edits it.

Preview width

Slider HSBA channels

Three inline sliders for hue, saturation and brightness, with format set to hsba, a blue to start and no alpha track. Brightness runs from black to the full color. Pick HSB when people come from a design tool that speaks in brightness rather than lightness, and the value string then reads hsba().

Preview width

Slider HSL channels

Hue, saturation and lightness on three inline sliders, with format set to hsla and a green to start. The lightness track runs from black through the color to white, where brightness in the HSBA demo stops at the full color. Use HSL when your stylesheet already writes colors as hsl(), so the stored string needs no conversion.

Preview width

Slider RGB channels

Red, green and blue each get an inline slider, with format set to rgba and no alpha track. Each track shows what moving that one channel does to the current color. Use RGB when the color is headed for a canvas, a shader or an API that takes those three numbers, so nothing converts it on the way out.

Preview width

Slider vertical

A single hue slider in an inline picker, with orientation set to vertical. The thumb counts hue from the top while the track's gradient runs from the bottom, so away from red the thumb sits over a different hue than the one it sets. For now a horizontal hue slider is the safer choice wherever people read the color off the track.

Preview width

Swatch picker

Four preset swatches, in blue, red, amber and green, sit in a ColorPickerSwatchGroup on an inline picker. Each ColorPickerSwatchTrigger holds a ColorPickerSwatch with a ColorPickerSwatchIndicator inside, which shows a check on the selected one, and nothing is checked until a click because the picker starts on black. Use swatches alone when the allowed colors are a short fixed list.

Preview width

Swatch picker controlled

The selected swatch comes from state, starting on blue, and the caption under the row prints it as hex through parseColor. Each click stores the picker's valueAsString, which is an rgba() string, so convert it wherever you need hex. Control the group when the choice is a saved setting, or another control on the page can change it.

Preview width

Swatch picker custom indicator

ColorPickerSwatchIndicator takes children, and here a sparkle icon replaces the default check on the selected swatch, which appears after the first click. Swap the icon to match the selected-state icon used elsewhere in your app. The indicator stays white with a 12 pixel icon, so add a class to it when the mark has to stand out on a light swatch such as amber.

Preview width

Swatch picker custom radius

Four swatches, each in a group of its own, with a corner radius class on ColorPickerSwatchTrigger that steps from rounded-sm to rounded-xl. The swatch inherits the trigger's radius, and the selection ring follows it. Match the radius to the buttons and cards around the picker, and keep one radius for a whole group.

Preview width

Swatch picker custom size

The triggers grow from size-4 to size-10 with a class on each ColorPickerSwatchTrigger, and the smallest leaves out ColorPickerSwatchIndicator, so only the ring marks it when selected. Use large swatches when they are the main control, especially on touch screens, and small ones as hints beside a slider.

Preview width

Swatch picker disabled

disabled on ColorPicker disables every ColorPickerSwatchTrigger. The swatches fade to half opacity and ignore clicks, while the colors stay visible. Use it to show a palette that is locked, such as one a workspace admin set. If this person will never pick, show the colors without buttons.

Preview width

With field

A Field puts a label and a line of help, asking for the brand's primary color, around the hex input, with no popover. Use it when the color sits in a form with other fields, so labels and hints line up. Ark UI names the input hex through an aria-label that outranks the visible label, so the demo passes an aria-label of "Color" to match it.

Preview width

FAQ

How do I get the selected color from the Color Picker in React?

Hold the color string in state, pass it as value, and set it from onValueChange, whose argument carries a parsed value and the string valueAsString. Store valueAsString, as the Input controlled demo does, since value on ColorPicker takes a string.

The string comes back in the picker's format, not as hex, so a picker that started from #eb5e41 reports rgba(235, 94, 65, 1).

How do I get a hex value from the Color Picker instead of rgba?

Convert the string with parseColor, which the component file exports: parseColor(value).toString("hex") returns #EB5E41. The picker has no hex format of its own. Its format is rgba, hsla or hsba, and without one it takes the format of the starting color, which is rgba for a hex code.

Hex drops the opacity. When an alpha slider or field can change it, use toString("hexa") for an eight-digit code such as #EB5E4180, or keep the rgba() string. A ColorPickerInput shows hex on its own, since hex is its default channel.

Why does my Color Picker throw an Invalid color value error?

parseColor couldn't read the string you passed, and the wrapper parses value and defaultValue while it renders. It reads hex codes of 3, 4, 6 or 8 digits, comma-separated rgb(), rgba(), hsl(), hsla(), hsb() and hsba(), and CSS color names such as red.

It rejects oklch(), which Tailwind CSS v4 uses for its theme colors, the space-separated form rgb(235 94 65), transparent and an empty value. Convert those to hex before they reach the picker. There is no empty state either: leave defaultValue out and the picker starts on black.

Why does my Color Picker hue slider ignore the arrow keys?

The slider's channel isn't part of the color the picker stores. A drag converts the color first, but the arrow keys, Home and End change the stored color directly, and when it has no such channel Ark UI throws an error instead. A picker that starts from a hex code with no format stores rgba, which has no hue, until a drag on the area or that slider stores the color as HSB.

Set format on ColorPicker to hsla or hsba for hue and saturation sliders, hsla for lightness, hsba for brightness and rgba for red, green and blue. Wrap the sliders in a ColorPickerView with the same format, since a view whose format differs from the picker's renders nothing.

How do I add preset color swatches to a Color Picker?

Put a ColorPickerSwatchGroup in the picker, and in it one ColorPickerSwatchTrigger per color, each with its value and a ColorPickerSwatch of the same value inside. A click sets the picker to that color, and a ColorPickerSwatchIndicator in the swatch shows a check while the picker's color matches it exactly, opacity included.

Swatches work inline, as in Swatch picker, or in the popover beside the area, as in Popover with swatch picker. A pick leaves the popover open, so set closeOnSelect on ColorPicker when a swatch should close it.

Does the Color Picker submit its value with a form?

It does once ColorPicker has a name. A hidden input carries the color string in the picker's format, such as hsla(10.24, 80.95%, 58.82%, 1), so convert it on the server if you store hex. A form reset puts back the starting color, and a disabled <fieldset> around the picker disables it.

This base's Field isn't Ark UI's, so its state doesn't reach the picker: set invalid or disabled on ColorPicker yourself. The With field demo puts a field around the hex input.

How do I save the Color Picker color only when the user stops dragging?

Save in onValueChangeEnd, and keep onValueChange for what has to follow every move, such as a live preview. The end callback runs when a drag on the area or a slider ends, when a typed channel is committed with Enter or by leaving the field, and after an eyedropper pick.

It doesn't run for arrow keys or swatch clicks, which only report the regular change. If those have to be saved too, debounce the regular change handler instead.

Why does the Color Picker eyedropper do nothing in Firefox or Safari?

ColorPickerEyeDropperTrigger opens the browser's EyeDropper API, which desktop Chromium browsers such as Chrome and Edge have and Firefox and Safari don't. Ark UI checks for it on click and returns quietly when it's missing, so the button renders everywhere and only works in some browsers.

Render the button only where the window has an EyeDropper constructor, and run that check after mount so the server and the first client render agree. Keep the area and the hex input as the main ways to pick a color.

API Reference

ColorPicker

<div> data-slot="color-picker"

PropType
format?"rgba" | "hsla" | "hsba"

The controlled color format to use.

Type
"rgba" | "hsla" | "hsba"
defaultFormat?"rgba" | "hsla" | "hsba"

The initial color format when rendered. Use when you don't need to control the color format of the color picker.

Type
"rgba" | "hsla" | "hsba"
Default
"rgba"
onFormatChange?(details: FormatChangeDetails) → void

Function called when the color format changes.

Type
(details: FormatChangeDetails) → void
Parameters

details – { format: ColorFormat }

Returns
void
open?boolean

The controlled open state of the color picker.

defaultOpen?boolean

The initial open state of the color picker when rendered. Use when you don't need to control the open state of the color picker.

onOpenChange?(details: OpenChangeDetails) → void

Handler that is called when the user opens or closes the color picker.

Type
(details: OpenChangeDetails) → void
Parameters

details – { open: boolean; value: Color }

Returns
void
value?string

The value of the color picker.

defaultValue?string

The default value of the color picker.

Default
#000000
onValueChange?(details: ValueChangeDetails) → void

Handler that is called when the value changes, as the user drags.

Type
(details: ValueChangeDetails) → void
Parameters

details – { value: Color; valueAsString: string }

Returns
void
closeOnSelect?boolean

Whether to close the color picker when a swatch is selected.

Default
false
dir?"ltr" | "rtl"

The document's text/writing direction.

Type
"ltr" | "rtl"
Default
"ltr"
disabled?boolean

Whether the color picker is disabled.

hideMode?"display-none" | "activity"

How to hide content when mounted but not present. - display-none: HTML hidden attribute. Effects stay alive. - activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.

Type
"display-none" | "activity"
Default
"display-none"
id?string

The unique identifier of the machine.

ids?object

The ids of the elements in the color picker. Useful for composition.

Type
{ root?: string; control?: string; trigger?: string; label?: string; input?: string; hiddenInput?: string; content?: string; area?: string; areaGradient?: string; positioner?: string; formatSelect?: string; areaThumb?: string; channelInput?: (id: string) → string; channelSliderTrack?: (id: ColorChannel) → string; channelSliderThumb?: (id: ColorChannel) → string }
immediate?boolean

Whether to synchronize the present change immediately or defer it to the next frame.

initialFocusEl?() → HTMLElement | null | false

The initial focus element when the color picker is opened. Return false to skip moving focus, or null to use the default.

Type
() → HTMLElement | null | false
Returns
HTMLElement | null | false
inline?boolean

Whether to render the color picker inline.

invalid?boolean

Whether the color picker is invalid.

lazyMount?boolean

Whether to enable lazy mounting. Ark default: false.

Default
true
name?string

The name for the form input.

onEnterComplete?VoidFunction

Function called when the animation ends in the open state.

onExitComplete?VoidFunction

Function called when the animation ends in the closed state.

onFocusOutside?(event: FocusOutsideEvent) → void

Function called when the focus is moved outside the component.

Type
(event: FocusOutsideEvent) → void
Parameters

event – FocusOutsideEvent

Returns
void
onInteractOutside?(event: InteractOutsideEvent) → void

Function called when an interaction happens outside the component.

Type
(event: InteractOutsideEvent) → void
Parameters

event – InteractOutsideEvent

Returns
void
onPointerDownOutside?(event: PointerDownOutsideEvent) → void

Function called when the pointer is pressed down outside the component.

Type
(event: PointerDownOutsideEvent) → void
Parameters

event – PointerDownOutsideEvent

Returns
void
onValueChangeEnd?(details: ValueChangeDetails) → void

Handler that is called when the user stops dragging.

Type
(details: ValueChangeDetails) → void
Parameters

details – { value: Color; valueAsString: string }

Returns
void
openAutoFocus?boolean

Whether to auto focus the color picker when it is opened.

Default
true
positioning?object

The positioning options for the color picker.

Type
{ restoreStyles?: boolean; applyStyles?: boolean; hideWhenDetached?: boolean; strategy?: "absolute" | "fixed"; placement?: Placement; offset?: { mainAxis?: number; crossAxis?: number; }; gutter?: number; shift?: number; overflowPadding?: number; arrowPadding?: number; flip?: boolean | Placement[]; slide?: boolean; overlap?: boolean; sameWidth?: boolean; fitViewport?: boolean; sizeMiddleware?: boolean; boundary?: (() → Boundary) | Boundary | "clipping-ancestors"; listeners?: boolean | AutoUpdateOptions; onComplete?: (data: ComputePositionReturn) → void; onPositioned?: ((data: { placed: boolean; }) → void); getAnchorElement?: () → HTMLElement | VirtualElement | null; getAnchorRect?: (element: HTMLElement | VirtualElement | null) → AnchorRect | null; updatePosition?: ((data: { updatePosition: () → Promise<void>; floatingElement: HTMLElement | null; }) → void | Promise<void>) }
Default
{ placement: "top-start" }
present?boolean

Whether the node is present (controlled by the user).

readOnly?boolean

Whether the color picker is read-only.

required?boolean

Whether the color picker is required.

skipAnimationOnMount?boolean

Whether to allow the initial presence animation.

Default
false
unmountOnExit?boolean

Whether to unmount on exit. Ark default: false.

Default
true
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled.

data-invalid?string

Present when invalid.

data-readonly?string

Present when read-only.

CSS variableType
--valuestring

The current value.

ColorPickerLabel

<label> data-slot="color-picker-label"

PropType
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled.

data-focus?string

Present when focused.

data-invalid?string

Present when invalid.

data-readonly?string

Present when read-only.

data-required?string

Present when required.

ColorPickerControl

<div> data-slot="color-picker-control"

PropType
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled.

data-focus?string

Present when focused.

data-invalid?string

Present when invalid.

data-readonly?string

Present when read-only.

data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"

ColorPickerTrigger

<button> data-slot="color-picker-trigger"

PropType
asChild?boolean

Merge props onto the child element instead of rendering a host.

AttributeType
data-disabled?string

Present when disabled.

data-focus?string

Present when focused.

data-invalid?string

Present when invalid.

data-placementstring

The placement of the trigger.

data-readonly?string

Present when read-only.

data-side"top" | "right" | "bottom" | "left"

The side of the trigger that the trigger is positioned on.

Type
"top" | "right" | "bottom" | "left"
data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"

ColorPickerTransparencyGrid

<div>

PropType
size?string

The size (width and height) of the element.

asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

CSS variableType
--sizestring

The size (width and height) of the element.

ColorPickerContent

<div> data-slot="color-picker-content"

PropType
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-has-nested?string

Present when another popover is nested inside it.

data-nested?string

Present when it's nested inside another popover.

data-placementstring

The placement of the content.

data-side"top" | "right" | "bottom" | "left"

The side of the trigger that the content is positioned on.

Type
"top" | "right" | "bottom" | "left"
data-state"open" | "closed"

"open" or "closed".

Type
"open" | "closed"
CSS variableType
--layer-indexstring

The index of the dismissable in the layer stack.

--nested-layer-countstring

The number of nested color-pickers.

--transform-originstring

Where the content scales from, on its trigger's side.

ColorPickerView

<div> data-slot="color-picker-view"

PropType
format"rgba" | "hsla" | "hsba"

The color format it's for: it renders only while the picker is in it.

Type
"rgba" | "hsla" | "hsba"
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

ColorPickerSlider

<div> data-slot="color-picker-channel-slider"

PropType
channel"hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha"

The channel it sets, such as hue or alpha.

Type
"hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha"
orientation?"horizontal" | "vertical"

Horizontal or vertical: the direction it runs.

Type
"horizontal" | "vertical"
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-channelstring

The color channel of the channelslider.

data-orientation"horizontal" | "vertical"

The orientation of the channelslider.

Type
"horizontal" | "vertical"

ColorPickerEyeDropperTrigger

<button> data-slot="color-picker-eye-dropper"

PropType
asChild?boolean

Merge props onto the child element instead of rendering a host.

AttributeType
data-disabled?string

Present when disabled.

data-invalid?string

Present when invalid.

data-readonly?string

Present when read-only.

ColorPickerSwatchGroup

<div> data-slot="color-picker-swatch-group"

PropType
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

ColorPickerSwatchTrigger

<button>

PropType
valuestring | Color

The color value.

Type
string | Color
disabled?boolean

Whether the swatch trigger is disabled.

asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled.

data-state"checked" | "unchecked"

"checked" or "unchecked".

Type
"checked" | "unchecked"
data-valuestring

The value of the item.

CSS variableType
--colorstring

The text color.

ColorPickerSwatch

<div> data-slot="color-picker-swatch"

PropType
valuestring | Color

The color value.

Type
string | Color
respectAlpha?boolean

Whether to include the alpha channel in the color.

asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-state"checked" | "unchecked"

"checked" or "unchecked".

Type
"checked" | "unchecked"
data-valuestring

The value of the item.

CSS variableType
--colorstring

The text color.

ColorPickerSwatchIndicator

<div> data-slot="color-picker-swatch-indicator"

PropType
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

ColorPickerValue

<span> data-slot="color-picker-value"

PropType
format?ColorHexFormat | ColorFormat | "rgb" | "hsl" | "hsb" | "css"

The format the value is written in.

Type
ColorHexFormat | ColorFormat | "rgb" | "hsl" | "hsb" | "css"
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled.

data-focus?string

Present when focused.

ColorPickerValueSwatch

<div> data-slot="color-picker-value-swatch"

PropType
respectAlpha?boolean

Whether to include the alpha channel in the color.

asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

ColorPickerArea

<div> data-slot="color-picker-area"

PropType
showDots?boolean

Lays a dot grid over the area, to read positions against.

Default
false
xChannel?"hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha"

The channel the area's horizontal axis sets.

Type
"hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha"
yChannel?"hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha"

The channel the area's vertical axis sets.

Type
"hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha"
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled.

data-invalid?string

Present when invalid.

data-readonly?string

Present when read-only.

ColorPickerAreaThumb

<div> data-slot="color-picker-area-thumb"

PropType
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled.

data-invalid?string

Present when invalid.

data-readonly?string

Present when read-only.

CSS variableType
--colorstring

The text color.

ColorPickerInput

<input> data-slot="color-picker-input"

PropType
channelColorChannel | "hex" | "css"

The channel it edits, or hex or css for the whole color as text.

Type
ColorChannel | "hex" | "css"
Default
"hex"
orientation?"horizontal" | "vertical"

The orientation its channel's arrow keys follow.

Type
"horizontal" | "vertical"
asChild?boolean

Merge props onto the child element instead of rendering a host.

AttributeType
data-channelstring

The color channel of the channelinput.

data-disabled?string

Present when disabled.

data-invalid?string

Present when invalid.

data-readonly?string

Present when read-only.

ColorPickerSwatchPreview

<div>

PropType
size?string

The size (width and height) of the element.

asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

CSS variableType
--sizestring

The size (width and height) of the element.

ColorPickerRootProvider

<div> data-slot="color-picker"

PropType
valueUseColorPickerReturn

What useColorPicker() returns: the state and API, made outside the component to control it.

hideMode?"display-none" | "activity"

How to hide content when mounted but not present. - display-none: HTML hidden attribute. Effects stay alive. - activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.

Type
"display-none" | "activity"
Default
"display-none"
immediate?boolean

Whether to synchronize the present change immediately or defer it to the next frame.

lazyMount?boolean

Whether to enable lazy mounting. Ark default: false.

Default
true
onEnterComplete?VoidFunction

Function called when the animation ends in the open state.

onExitComplete?VoidFunction

Function called when the animation ends in the closed state.

present?boolean

Whether the node is present (controlled by the user).

skipAnimationOnMount?boolean

Whether to allow the initial presence animation.

Default
false
unmountOnExit?boolean

Whether to unmount on exit. Ark default: false.

Default
true
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when disabled is true.

data-invalid?string

Present when invalid is true.

data-readonly?string

Present when readOnly is true.

CSS variableType
--valuestring

useColorPicker

PropType
format?"rgba" | "hsla" | "hsba"

The controlled color format to use.

Type
"rgba" | "hsla" | "hsba"
defaultFormat?"rgba" | "hsla" | "hsba"

The initial color format when rendered. Use when you don't need to control the color format of the color picker.

Type
"rgba" | "hsla" | "hsba"
Default
"rgba"
onFormatChange?(details: FormatChangeDetails) → void

Function called when the color format changes.

Type
(details: FormatChangeDetails) → void
Parameters

details – { format: ColorFormat }

Returns
void
open?boolean

The controlled open state of the color picker.

defaultOpen?boolean

The initial open state of the color picker when rendered. Use when you don't need to control the open state of the color picker.

onOpenChange?(details: OpenChangeDetails) → void

Handler that is called when the user opens or closes the color picker.

Type
(details: OpenChangeDetails) → void
Parameters

details – { open: boolean; value: Color }

Returns
void
value?Color

The controlled color value of the color picker.

defaultValue?Color

The initial color value when rendered. Use when you don't need to control the color value of the color picker.

Default
#000000
onValueChange?(details: ValueChangeDetails) → void

Handler that is called when the value changes, as the user drags.

Type
(details: ValueChangeDetails) → void
Parameters

details – { value: Color; valueAsString: string }

Returns
void
closeOnSelect?boolean

Whether to close the color picker when a swatch is selected.

Default
false
disabled?boolean

Whether the color picker is disabled.

id?string

The unique identifier of the machine.

ids?object

The ids of the elements in the color picker. Useful for composition.

Type
{ root?: string; control?: string; trigger?: string; label?: string; input?: string; hiddenInput?: string; content?: string; area?: string; areaGradient?: string; positioner?: string; formatSelect?: string; areaThumb?: string; channelInput?: (id: string) → string; channelSliderTrack?: (id: ColorChannel) → string; channelSliderThumb?: (id: ColorChannel) → string }
initialFocusEl?() → HTMLElement | null | false

The initial focus element when the color picker is opened. Return false to skip moving focus, or null to use the default.

Type
() → HTMLElement | null | false
Returns
HTMLElement | null | false
inline?boolean

Whether to render the color picker inline.

invalid?boolean

Whether the color picker is invalid.

name?string

The name for the form input.

onFocusOutside?(event: FocusOutsideEvent) → void

Function called when the focus is moved outside the component.

Type
(event: FocusOutsideEvent) → void
Parameters

event – FocusOutsideEvent

Returns
void
onInteractOutside?(event: InteractOutsideEvent) → void

Function called when an interaction happens outside the component.

Type
(event: InteractOutsideEvent) → void
Parameters

event – InteractOutsideEvent

Returns
void
onPointerDownOutside?(event: PointerDownOutsideEvent) → void

Function called when the pointer is pressed down outside the component.

Type
(event: PointerDownOutsideEvent) → void
Parameters

event – PointerDownOutsideEvent

Returns
void
onValueChangeEnd?(details: ValueChangeDetails) → void

Handler that is called when the user stops dragging.

Type
(details: ValueChangeDetails) → void
Parameters

details – { value: Color; valueAsString: string }

Returns
void
openAutoFocus?boolean

Whether to auto focus the color picker when it is opened.

Default
true
positioning?object

The positioning options for the color picker.

Type
{ restoreStyles?: boolean; applyStyles?: boolean; hideWhenDetached?: boolean; strategy?: "absolute" | "fixed"; placement?: Placement; offset?: { mainAxis?: number; crossAxis?: number; }; gutter?: number; shift?: number; overflowPadding?: number; arrowPadding?: number; flip?: boolean | Placement[]; slide?: boolean; overlap?: boolean; sameWidth?: boolean; fitViewport?: boolean; sizeMiddleware?: boolean; boundary?: (() → Boundary) | Boundary | "clipping-ancestors"; listeners?: boolean | AutoUpdateOptions; onComplete?: (data: ComputePositionReturn) → void; onPositioned?: ((data: { placed: boolean; }) → void); getAnchorElement?: () → HTMLElement | VirtualElement | null; getAnchorRect?: (element: HTMLElement | VirtualElement | null) → AnchorRect | null; updatePosition?: ((data: { updatePosition: () → Promise<void>; floatingElement: HTMLElement | null; }) → void | Promise<void>) }
readOnly?boolean

Whether the color picker is read-only.

required?boolean

Whether the color picker is required.

ColorPickerContext

PropType
alphanumber

The alpha value of the color.

draggingboolean

Whether the color picker is being dragged.

format"rgba" | "hsla" | "hsba"

The current color format.

Type
"rgba" | "hsla" | "hsba"
getChannelValue(channel: ColorChannel) → string

Function to set the color value.

Parameters

channel – ColorChannel

Returns
string
getChannelValueText(channel: ColorChannel, locale: string) → string

Function to get the formatted and localized value of a specific channel.

Type
(channel: ColorChannel, locale: string) → string
Parameters

channel – ColorChannel

locale – string

Returns
string
getSwatchTriggerState(props: SwatchTriggerProps) → SwatchTriggerState

A swatch trigger's state for its props: its value, and whether it's checked or disabled.

Type
(props: SwatchTriggerProps) → SwatchTriggerState
Parameters

props – { value: string | Color; disabled?: boolean }

Returns
SwatchTriggerState
inlineboolean

Whether the color picker is rendered inline.

openboolean

Whether the color picker is open.

setAlpha(value: number) → void

Function to set the color alpha.

Parameters

value – number

Returns
void
setChannelValue(channel: ColorChannel, value: number) → void

Function to set the color value of a specific channel.

Type
(channel: ColorChannel, value: number) → void
Parameters

channel – ColorChannel

value – number

Returns
void
setFormat(format: ColorFormat) → void

Function to set the color format.

Parameters

format – ColorFormat

Returns
void
setOpen(open: boolean) → void

Function to open or close the color picker.

Parameters

open – boolean

Returns
void
setValue(value: string | Color) → void

Function to set the color value.

Type
(value: string | Color) → void
Parameters

value – string | Color

Returns
void
valueColor

The current color value (as a string).

valueAsStringstring

The current color value (as a Color object).