Color Picker
A component that allows users to select a color from a color picker.
A component that allows users to select a color from a color picker.
Please note, the API of this component is currently in a preview phase and is subject to change.
Saved Colors
To set up the color picker correctly, you’ll need to understand its anatomy and how we name its parts.
Each part includes a
data-part
attribute to help identify them in the DOM.
Learn how to use the ColorPicker
component in your project. Let’s take a look
at the most basic example
import { ColorPicker } from '@ark-ui/react'
const Basic = () => {
return (
<ColorPicker.Root defaultValue="#eb5e41">
{(api) => (
<>
<ColorPicker.Label>Color</ColorPicker.Label>
<ColorPicker.Control>
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
<ColorPicker.ValueText />
<ColorPicker.Trigger>
<ColorPicker.TransparencyGrid />
<ColorPicker.Swatch value={api.value} />
</ColorPicker.Trigger>
</ColorPicker.Control>
<ColorPicker.Positioner>
<ColorPicker.Content>
<ColorPicker.FormatTrigger>Toggle ColorFormat</ColorPicker.FormatTrigger>
<ColorPicker.FormatSelect />
<ColorPicker.Area>
<ColorPicker.AreaBackground />
<ColorPicker.AreaThumb />
</ColorPicker.Area>
<ColorPicker.ChannelSlider channel="hue">
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.ChannelSlider channel="alpha">
<ColorPicker.TransparencyGrid />
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.SwatchGroup>
<ColorPicker.SwatchTrigger value="red">
<ColorPicker.Swatch value="red">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="blue">
<ColorPicker.Swatch value="blue">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="green">
<ColorPicker.Swatch value="green">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
</ColorPicker.SwatchGroup>
<ColorPicker.View format="rgba">
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
</ColorPicker.View>
<ColorPicker.View format="hsla">
<ColorPicker.ChannelInput channel="hue" />
<ColorPicker.ChannelInput channel="saturation" />
<ColorPicker.ChannelInput channel="lightness" />
</ColorPicker.View>
<ColorPicker.EyeDropperTrigger>Pick color</ColorPicker.EyeDropperTrigger>
</ColorPicker.Content>
</ColorPicker.Positioner>
</>
)}
</ColorPicker.Root>
)
}
import { ColorPicker } from '@ark-ui/solid'
const Basic = () => {
return (
<ColorPicker.Root value="#eb5e41">
{(api) => (
<>
<ColorPicker.Label>Color</ColorPicker.Label>
<ColorPicker.Control>
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
<ColorPicker.ValueText />
<ColorPicker.Trigger>
<ColorPicker.TransparencyGrid />
<ColorPicker.Swatch value={api().value} />
</ColorPicker.Trigger>
</ColorPicker.Control>
<ColorPicker.Positioner>
<ColorPicker.Content>
<ColorPicker.FormatTrigger>Toggle ColorFormat</ColorPicker.FormatTrigger>
<ColorPicker.FormatSelect />
<ColorPicker.Area>
<ColorPicker.AreaBackground />
<ColorPicker.AreaThumb />
</ColorPicker.Area>
<ColorPicker.ChannelSlider channel="hue">
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.ChannelSlider channel="alpha">
<ColorPicker.TransparencyGrid />
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.SwatchGroup>
<ColorPicker.SwatchTrigger value="red">
<ColorPicker.Swatch value="red">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="blue">
<ColorPicker.Swatch value="blue">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="green">
<ColorPicker.Swatch value="green">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
</ColorPicker.SwatchGroup>
<ColorPicker.View format="rgba">
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
</ColorPicker.View>
<ColorPicker.View format="hsla">
<ColorPicker.ChannelInput channel="hue" />
<ColorPicker.ChannelInput channel="saturation" />
<ColorPicker.ChannelInput channel="lightness" />
</ColorPicker.View>
<ColorPicker.EyeDropperTrigger>Pick color</ColorPicker.EyeDropperTrigger>
</ColorPicker.Content>
</ColorPicker.Positioner>
</>
)}
</ColorPicker.Root>
)
}
<script setup lang="ts">
import { ref } from 'vue'
import { ColorPicker } from '@ark-ui/vue'
const value = ref('hsl(20, 100%, 50%)')
</script>
<template>
<ColorPicker.Root #default="api" :modelValue="'#eb5e41'">
<ColorPicker.Label>Color</ColorPicker.Label>
<ColorPicker.Control>
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
<ColorPicker.ValueText />
<ColorPicker.Trigger>
<ColorPicker.TransparencyGrid />
<ColorPicker.Swatch :value="api.value" />
</ColorPicker.Trigger>
</ColorPicker.Control>
<ColorPicker.Positioner>
<ColorPicker.Content>
<ColorPicker.FormatTrigger>Toggle ColorFormat</ColorPicker.FormatTrigger>
<ColorPicker.FormatSelect />
<ColorPicker.Area>
<ColorPicker.AreaBackground />
<ColorPicker.AreaThumb />
</ColorPicker.Area>
<ColorPicker.ChannelSlider channel="hue">
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.ChannelSlider channel="alpha">
<ColorPicker.TransparencyGrid />
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.SwatchGroup>
<ColorPicker.SwatchTrigger value="red">
<ColorPicker.Swatch value="red">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="blue">
<ColorPicker.Swatch value="blue">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="green">
<ColorPicker.Swatch value="green">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
</ColorPicker.SwatchGroup>
<ColorPicker.View format="rgba">
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
</ColorPicker.View>
<ColorPicker.View format="hsla">
<ColorPicker.ChannelInput channel="hue" />
<ColorPicker.ChannelInput channel="saturation" />
<ColorPicker.ChannelInput channel="lightness" />
</ColorPicker.View>
<ColorPicker.EyeDropperTrigger>Pick color</ColorPicker.EyeDropperTrigger>
</ColorPicker.Content>
</ColorPicker.Positioner>
</ColorPicker.Root>
</template>
To create a controlled Color Picker component, manage the state of the current
color using the value
prop and update it when the onValueChange
or
onValueChangeEnd
event handler is called:
import { ColorPicker } from '@ark-ui/react'
import { useState } from 'react'
const Controlled = () => {
const [currentValue, setCurrentValue] = useState('hsl(20, 100%, 50%)')
return (
<ColorPicker.Root
format="hsla"
value={currentValue}
onValueChange={(details) => setCurrentValue(details.valueAsString)}
onValueChangeEnd={(details) => console.log(details.valueAsString)}
>
{(api) => (
<>
<ColorPicker.Label>Color</ColorPicker.Label>
<ColorPicker.Control>
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
<ColorPicker.ValueText />
<ColorPicker.Trigger>
<ColorPicker.TransparencyGrid />
<ColorPicker.Swatch value={api.value} />
</ColorPicker.Trigger>
</ColorPicker.Control>
<ColorPicker.Positioner>
<ColorPicker.Content>
<ColorPicker.Area>
<ColorPicker.AreaBackground />
<ColorPicker.AreaThumb />
</ColorPicker.Area>
<ColorPicker.ChannelSlider channel="hue">
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.ChannelSlider channel="alpha">
<ColorPicker.TransparencyGrid />
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.SwatchGroup>
<ColorPicker.SwatchTrigger value="red">
<ColorPicker.Swatch value="red">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="blue">
<ColorPicker.Swatch value="blue">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="green">
<ColorPicker.Swatch value="green">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
</ColorPicker.SwatchGroup>
<ColorPicker.View format="rgba">
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
</ColorPicker.View>
<ColorPicker.View format="hsla">
<ColorPicker.ChannelInput channel="hue" />
<ColorPicker.ChannelInput channel="saturation" />
<ColorPicker.ChannelInput channel="lightness" />
</ColorPicker.View>
<ColorPicker.EyeDropperTrigger>Pick color</ColorPicker.EyeDropperTrigger>
</ColorPicker.Content>
</ColorPicker.Positioner>
</>
)}
</ColorPicker.Root>
)
}
import { ColorPicker } from '@ark-ui/solid'
import { createSignal } from 'solid-js'
const Controlled = () => {
const [currentValue, setCurrentValue] = createSignal('hsl(0, 100%, 50%)')
return (
<ColorPicker.Root
value={currentValue()}
onValueChange={(details) => setCurrentValue(details.valueAsString)}
onValueChangeEnd={(details) => console.log(details.valueAsString)}
>
{(api) => (
<>
<ColorPicker.Label>Color</ColorPicker.Label>
<ColorPicker.Control>
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
<ColorPicker.ValueText />
<ColorPicker.Trigger>
<ColorPicker.TransparencyGrid />
<ColorPicker.Swatch value={api().value} />
</ColorPicker.Trigger>
</ColorPicker.Control>
<ColorPicker.Positioner>
<ColorPicker.Content>
<ColorPicker.Area>
<ColorPicker.AreaBackground />
<ColorPicker.AreaThumb />
</ColorPicker.Area>
<ColorPicker.ChannelSlider channel="hue">
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.ChannelSlider channel="alpha">
<ColorPicker.TransparencyGrid />
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.SwatchGroup>
<ColorPicker.SwatchTrigger value="red">
<ColorPicker.Swatch value="red">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="blue">
<ColorPicker.Swatch value="blue">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="green">
<ColorPicker.Swatch value="green">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
</ColorPicker.SwatchGroup>
<ColorPicker.View format="rgba">
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
</ColorPicker.View>
<ColorPicker.View format="hsla">
<ColorPicker.ChannelInput channel="hue" />
<ColorPicker.ChannelInput channel="saturation" />
<ColorPicker.ChannelInput channel="lightness" />
</ColorPicker.View>
<ColorPicker.EyeDropperTrigger>Pick color</ColorPicker.EyeDropperTrigger>
</ColorPicker.Content>
</ColorPicker.Positioner>
</>
)}
</ColorPicker.Root>
)
}
<script setup lang="ts">
import { ref } from 'vue'
import { ColorPicker } from '@ark-ui/vue'
const value = ref('hsl(20, 100%, 50%)')
</script>
<template>
<ColorPicker.Root
#default="api"
format="hsla"
v-model="value"
@value-change="(details) => (value = details.valueAsString)"
@value-change-end="(details) => console.log(details.valueAsString)"
>
<ColorPicker.Label>Color</ColorPicker.Label>
<ColorPicker.Control>
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
<ColorPicker.ValueText />
<ColorPicker.Trigger>
<ColorPicker.TransparencyGrid />
<ColorPicker.Swatch :value="api.value" />
</ColorPicker.Trigger>
</ColorPicker.Control>
<ColorPicker.Positioner>
<ColorPicker.Content>
<ColorPicker.Area>
<ColorPicker.AreaBackground />
<ColorPicker.AreaThumb />
</ColorPicker.Area>
<ColorPicker.ChannelSlider channel="hue">
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.ChannelSlider channel="alpha">
<ColorPicker.TransparencyGrid />
<ColorPicker.ChannelSliderTrack />
<ColorPicker.ChannelSliderThumb />
</ColorPicker.ChannelSlider>
<ColorPicker.SwatchGroup>
<ColorPicker.SwatchTrigger value="red">
<ColorPicker.Swatch value="red">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="blue">
<ColorPicker.Swatch value="blue">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
<ColorPicker.SwatchTrigger value="green">
<ColorPicker.Swatch value="green">
<ColorPicker.SwatchIndicator>✓</ColorPicker.SwatchIndicator>
</ColorPicker.Swatch>
</ColorPicker.SwatchTrigger>
</ColorPicker.SwatchGroup>
<ColorPicker.View format="rgba">
<ColorPicker.ChannelInput channel="hex" />
<ColorPicker.ChannelInput channel="alpha" />
</ColorPicker.View>
<ColorPicker.View format="hsla">
<ColorPicker.ChannelInput channel="hue" />
<ColorPicker.ChannelInput channel="saturation" />
<ColorPicker.ChannelInput channel="lightness" />
</ColorPicker.View>
<ColorPicker.EyeDropperTrigger>Pick color</ColorPicker.EyeDropperTrigger>
</ColorPicker.Content>
</ColorPicker.Positioner>
</ColorPicker.Root>
</template>
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean | |
closeOnSelect Whether to close the color picker when a swatch is selected | boolean | |
defaultValue The initial value of the color picker. | string | |
dir The direction of the color picker | 'ltr' | 'rtl' | |
disabled Whether the color picker is disabled | boolean | |
format The color format to use | ColorFormat | |
getRootNode A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | () => Node | ShadowRoot | Document | |
id The unique identifier of the machine. | string | |
ids The ids of the elements in the color picker. Useful for composition. | Partial<{
root: string
control: string
trigger: string
label: string
input: string
content: string
area: string
areaGradient: string
areaThumb: string
channelInput(id: string): string
channelSliderTrack(id: ColorChannel): string
channelSliderThumb(id: ColorChannel): string
}> | |
initialFocusEl The initial focus element when the color picker is opened. | HTMLElement | (() => MaybeElement) | |
lazyMount Whether to enable lazy mounting | boolean | false |
name The name for the form input | string | |
onExitComplete Function called when the animation ends in the closed state. | () => void | |
onFocusOutside Function called when the focus is moved outside the component | (event: FocusOutsideEvent) => void | |
onFormatChange Function called when the color format changes | (details: FormatChangeDetails) => void | |
onInteractOutside Function called when an interaction happens outside the component | (event: InteractOutsideEvent) => void | |
onOpenChange Handler that is called when the user opens or closes the color picker. | (details: OpenChangeDetails) => void | |
onPointerDownOutside Function called when the pointer is pressed down outside the component | (event: PointerDownOutsideEvent) => void | |
onValueChange Handler that is called when the value changes, as the user drags. | (details: ValueChangeDetails) => void | |
onValueChangeEnd Handler that is called when the user stops dragging. | (details: ValueChangeDetails) => void | |
open Whether the color picker is open | boolean | |
positioning The positioning options for the color picker | PositioningOptions | |
present Whether the node is present (controlled by the user) | boolean | |
readOnly Whether the color picker is read-only | boolean | |
unmountOnExit Whether to unmount on exit. | boolean | false |
value The current value of the color picker. | string |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean | |
xChannel | ColorChannel | |
yChannel | ColorChannel |
Prop | Type | Default |
---|---|---|
format | ColorFormat | |
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
value The color value | string | Color | |
asChild Render as a different element type. | boolean | |
respectAlpha Whether to include the alpha channel in the color | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
channel | ExtendedColorChannel | |
asChild Render as a different element type. | boolean | |
orientation | Orientation |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
channel | ColorChannel | |
asChild Render as a different element type. | boolean | |
orientation | Orientation |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
value The color value | string | Color | |
asChild Render as a different element type. | boolean | |
disabled Whether the swatch trigger is disabled | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean | |
size | string |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |