Skip to Content
Documentation
Getting startedComponentsChartsTheming
Get Pro
Overview
Concepts

Color Picker

Used to select colors from a color area or a set of defined swatches.

Recipe

Anatomy

import { ColorPicker } from '@chakra-ui/react'
<ColorPicker.Root>
  <ColorPicker.HiddenInput />
  <ColorPicker.Label />
  <ColorPicker.Control>
    <ColorPicker.Input />
    <ColorPicker.Trigger />
  </ColorPicker.Control>
  <ColorPicker.Positioner>
    <ColorPicker.Content>
      <ColorPicker.Area />
      <ColorPicker.EyeDropper />
      <ColorPicker.Sliders />
      <ColorPicker.SwatchGroup>
        <ColorPicker.SwatchTrigger>
          <ColorPicker.Swatch />
        </ColorPicker.SwatchTrigger>
      </ColorPicker.SwatchGroup>
    </ColorPicker.Content>
  </ColorPicker.Positioner>
</ColorPicker.Root>

Shortcuts

Some parts are shortcuts that render a group of parts for you.

ColorPicker.Area renders the area background and thumb:

<ColorPicker.Area>
  <ColorPicker.AreaThumb />
  <ColorPicker.AreaBackground />
</ColorPicker.Area>

ColorPicker.ChannelSlider renders the transparency grid, track and thumb:

<ColorPicker.ChannelSlider>
  <ColorPicker.TransparencyGrid />
  <ColorPicker.ChannelSliderTrack />
  <ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>

ColorPicker.Sliders renders both the hue and alpha channel sliders:

<Stack>
  <ColorPicker.ChannelSlider channel="hue" />
  <ColorPicker.ChannelSlider channel="alpha" />
</Stack>

ColorPicker.EyeDropper renders an icon button wired to the eye dropper trigger:

<ColorPicker.EyeDropperTrigger asChild>
  <IconButton>
    <LuPipette />
  </IconButton>
</ColorPicker.EyeDropperTrigger>

Examples

Basic

Use parseColor to create the initial color value, and compose the input and trigger inside ColorPicker.Control.

Sizes

Use the size prop to change the size of the color picker.

Variants

Use the variant prop to change the visual style of the color picker. Values can be either outline or subtle.

Controlled

Use the value and onValueChange props to control the state of the color picker.

Swatches

Render a ColorPicker.SwatchGroup inside the content to offer a set of predefined colors alongside the color area.

Input Only

Combine ColorPicker.ValueSwatch and ColorPicker.EyeDropper with an InputGroup to render a color picker that consists of only an input.

Inline

Pass the open prop to render the color picker inline, without a popover.

Guide

Getting the hex code

Use the onValueChange callback to get the color value. The value object has a toString() method that accepts different format options.

<ColorPicker.Root
  onValueChange={(details) => {
    console.log(details.value.toString('hex')) // "#ff0000"
    console.log(details.value.toString('hexa')) // "#ff0000ff" (with alpha)
    console.log(details.value.toString('rgb')) // "rgb(255, 0, 0)"
    console.log(details.value.toString('css')) // CSS color string
  }}
>
  {/* ... */}
</ColorPicker.Root>

You can also access it from the store:

const picker = useColorPicker() // or useColorPickerContext()
const hexValue = picker.value.toString('hex') // "#ff0000"

The same toString() method is available when using parseColor:

import { parseColor } from '@chakra-ui/react'

const color = parseColor('#ff0000')
console.log(color.toString('hex')) // "#ff0000"
console.log(color.toString('rgba')) // "rgba(255, 0, 0, 1)"

Props

Root

PropDefaultType
closeOnSelect false
boolean

Whether to close the color picker when a swatch is selected

defaultFormat '\'rgba\''
ColorFormat

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

defaultValue '#000000'
Color

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

hideMode ''display-none''
HideMode

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+.

lazyMount false
boolean

Whether to enable lazy mounting

openAutoFocus true
boolean

Whether to auto focus the color picker when it is opened

skipAnimationOnMount false
boolean

Whether to allow the initial presence animation.

unmountOnExit false
boolean

Whether to unmount on exit.

colorPalette 'gray'
'base' | 'gray' | 'zinc' | 'neutral' | 'stone' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'sidebar' | 'sidebar.accent' | 'interaction' | 'accent' | 'presence' | 'status' | 'slate'

The color palette of the component

size 'md'
'2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'

The size of the component

variant 'outline'
'outline' | 'subtle'

The variant of the component

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
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.

disabled
boolean

Whether the color picker is disabled

format
ColorFormat

The controlled color format to use

id
string

The unique identifier of the machine.

ids
Partial<{ 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; channe...

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

immediate
boolean

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

initialFocusEl
() => HTMLElement | null

The initial focus element when the color picker is opened.

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

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

onFormatChange
(details: FormatChangeDetails) => void

Function called when the color format changes

onInteractOutside
(event: InteractOutsideEvent) => void

Function called when an interaction happens outside the component

onOpenChange
(details: OpenChangeDetails) => void

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

onPointerDownOutside
(event: PointerDownOutsideEvent) => void

Function called when the pointer is pressed down outside the component

onValueChange
(details: ValueChangeDetails) => void

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

onValueChangeEnd
(details: ValueChangeDetails) => void

Handler that is called when the user stops dragging.

open
boolean

The controlled open state of the color picker

positioning
PositioningOptions

The positioning options for the color picker

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

value
Color

The controlled color value of the color picker