Skip to content

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

Components

Free

Color Picker for Svelte UI SDK

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

On this page9 sections

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 UI SDK's color picker, wrapped to keep the other bases' props.

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

<script lang="ts">
import {
  ColorPicker, ColorPickerArea, ColorPickerAreaThumb,
  ColorPickerContent, ColorPickerControl, ColorPickerEyeDropperTrigger,
  ColorPickerInput, ColorPickerSlider, ColorPickerSwatchPreview,
  ColorPickerTransparencyGrid, ColorPickerTrigger, ColorPickerView,
} from "@/components/ui/color-picker"
import {
  InputGroup, InputGroupAddon, InputGroupInput,
} from "@/components/ui/input-group"
</script>
<ColorPicker class="w-full max-w-xs" defaultValue="#EB5E41" format="hsla" positioning={{ placement: "bottom-start" }}><ColorPickerControl><InputGroup><InputGroupAddon><ColorPickerTrigger class="rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring"><ColorPickerSwatchPreview /></ColorPickerTrigger></InputGroupAddon><ColorPickerInput>{#snippet render({ props })}<InputGroupInput {...props} class="font-mono uppercase" />{/snippet}</ColorPickerInput></InputGroup></ColorPickerControl><ColorPickerContent><ColorPickerArea><ColorPickerAreaThumb /></ColorPickerArea><ColorPickerView format="hsla"><div class="flex items-center gap-2"><ColorPickerEyeDropperTrigger /><div class="flex min-w-0 flex-1 flex-col gap-2"><ColorPickerSlider channel="hue" /><ColorPickerSlider channel="alpha"><ColorPickerTransparencyGrid /></ColorPickerSlider></div></div></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 slider named for both its channels, such as Saturation and brightness, and each channel slider is a plain one named for its channel. The hex input is named Hex, and a channel input Red, Alpha and so on, by an aria-label that outranks any <label>, so pass ColorPickerInput an aria-label matching its visible label, as With field does. The swatches are a listbox with one tab stop: each is named by its color, and the selected one is marked with aria-selected.

Enter
When focus is on the trigger, opens the color picker. When focus is on a swatch, selects its color (and closes the color picker when closeOnSelect is set). In the hex input or a channel input, applies what was typed, and text that isn't a color goes back.
Arrow Left
When focus is on the color area, decreases its horizontal channel, saturation unless xChannel or an rgba format sets another. When focus is on a channel slider, decreases its channel. On a swatch, moves focus to the previous one. Right to left, it does what ArrowRight does, and with Shift it moves ten steps.
Arrow Right
When focus is on the color area, increases its horizontal channel, saturation unless xChannel or an rgba format sets another. When focus is on a channel slider, increases its channel. On a swatch, moves focus to the next one. Right to left, it does what ArrowLeft does, and with Shift it moves ten steps.
Arrow Up
When focus is on the color area, increases its vertical channel, brightness (lightness with an hsla format, green with rgba) unless yChannel sets another. When focus is on a channel slider, increases its channel. On a swatch, moves focus to the previous one. With Shift, it moves ten steps.
Arrow Down
When focus is on the color area, decreases its vertical channel, brightness (lightness with an hsla format, green with rgba) unless yChannel sets another. When focus is on a channel slider, decreases its channel. On a swatch, moves focus to the next one. With Shift, it moves ten steps.
Escape
Closes the color picker and moves focus to the trigger. In the hex input, the first press puts back text typed since the last color was read, and the next one closes.
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 vertical channel by a tenth of its range. When focus is on a channel slider, increases its channel by a tenth of its range.
Page Down
When focus is on the color area, decreases its vertical channel by a tenth of its range. When focus is on a channel slider, decreases its channel by a tenth of its range.
Home
When focus is on the color area, sets its horizontal channel to its minimum. When focus is on a channel slider, sets that channel to its minimum. On a swatch, moves focus to the first one.
End
When focus is on the color area, sets its horizontal channel to its maximum. When focus is on a channel slider, sets that channel to its maximum. On a swatch, moves focus to the last one.

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 a percentage, from 0 to 100, though the color's toString() still writes it from 0 to 1. 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 string the new color's toString() gives. 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 would edit blue instead, 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. Its defaultValue goes through parseColor, though this hook takes the plain string too. 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 and the track's gradient both count hue from the bottom, so the thumb always sits over the hue it sets. Use it beside a tall area, or in a panel with more height than width.

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 new color's toString(), 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. This file names the hex 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 Svelte?

Hold the color in $state and bind it with bind:value, or pass it as value and set it from onValueChange, which receives the new color first, as a parsed color. value takes a string or a parsed color, so the Input controlled demo stores the string from the color's toString().

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 rgba when you set none, whatever the starting color.

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?

On this base only parseColor throws it, when your own code calls it on text that isn't a color, as the demos do to print hex. The picker itself reads value and defaultValue with UI SDK's parser and doesn't throw.

That parser takes any CSS color, so oklch() from the Tailwind CSS v4 theme, the space-separated form rgb(235 94 65) and transparent all work, and so does hsba(). parseColor reads the same strings. There is no empty state: leave defaultValue out and the picker starts on black.

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

On this base it shouldn't. Without a format, the picker edits hue, saturation and brightness, so a hue slider's arrow keys, Home and End work from the start. A slider's channel has to be one the format has, though: with format set to rgba, which has no hue, a hue slider edits blue instead.

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 as hex, such as #eb5e41, whatever the picker's format, with two more digits for the opacity when the color isn't opaque. A form reset puts back the starting color, and a disabled <fieldset> around the picker disables it.

The Field here is UI SDK's, and the picker is its control, so a disabled field disables the area, the sliders and the inputs, and an invalid one marks the trigger and the inputs with aria-invalid. The Input invalid demo puts the picker in a Field marked invalid.

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.

Each arrow key press and swatch click runs it too, since each one finishes its change, so a value saved from it is never a step behind.

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. UI SDK checks for it once the button mounts and disables the button where it's missing, marking it with data-unsupported, so it 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
open?boolean

Whether the popup is open. Pass it to control the popup. Two-way with bind:open.

defaultOpen?boolean

Whether the popup starts open, when uncontrolled.

Default
false
onOpenChange?(details: ColorPickerOpenChangeDetails) → void

Called when it opens or closes.

Type
(details: ColorPickerOpenChangeDetails) → void
Parameters

details – { open: boolean }

Returns
void
value?string

The value, as any CSS color or hsba(…). Pass it to control the picker. Two-way with bind:value.

defaultValue?string

The value at first, as any CSS color or hsba(…). A form reset returns to it.

Default
"#000000"
onValueChange?(details: ColorPickerValueChangeDetails) → void

Runs on every step of a drag or a key.

Type
(details: ColorPickerValueChangeDetails) → void
Parameters

details – { value: ColorValue; valueAsString: string }

Returns
void
closeOnSelect?boolean

Closes the popup once a swatch is picked. @default false.

Default
false
controller?{ getValue: () → string; setValue: (value: string, options?: ColorPickerChangeOptions) → boolean; focus: () → void; }

Sets the value from anywhere. Create one with createColorPickerController().

Type
{ getValue: () → string; setValue: (value: string, options?: ColorPickerChangeOptions) → boolean; focus: () → void; }
debug?boolean

Logs every state change with its reason to the console, in development builds.

disabled?boolean

Disables every part: they can't be focused or changed, and the value isn't submitted.

Default
false
form?string

The id of a form to belong to, when it isn't inside that form.

format?ColorFormat

How valueAsString is written, and the channels the sliders and inputs edit. An area edits saturation and brightness in hsba (and without a format), saturation and lightness in hsla, red and green in rgba.

Default
"rgba"
gamut?false | ColorGamut

The colors the value can hold. A drag can go past the edge, and the value is the closest color inside it; once the drag ends, the picker moves there too. "p3" allows wide-gamut screens' colors, and false any color.

Type
false | ColorGamut
Default
"srgb"
inline?boolean

Lays the parts out in place, without a popup.

Default
false
invalid?boolean

Marks the picker and its inputs invalid.

Default
false
lazyMount?boolean

Kept for the other bases: the popup mounts as it opens.

Default
false
name?string

The name the value submits under. Without one, the picker submits nothing.

onFocusOutside?(event: ColorPickerInteractOutsideEvent) → void

Called when focus moves outside it. Prevent its default to keep it open.

Type
(event: ColorPickerInteractOutsideEvent) → void
Parameters

event – ColorPickerInteractOutsideEvent

Returns
void
onInteractOutside?(event: ColorPickerInteractOutsideEvent) → void

Runs before a press or focus outside closes the popup. event.preventDefault() keeps it open.

Type
(event: ColorPickerInteractOutsideEvent) → void
Parameters

event – ColorPickerInteractOutsideEvent

Returns
void
onPointerDownOutside?(event: ColorPickerInteractOutsideEvent) → void

Called when a pointer goes down outside it. Prevent its default to keep it open.

Type
(event: ColorPickerInteractOutsideEvent) → void
Parameters

event – ColorPickerInteractOutsideEvent

Returns
void
onValueChangeEnd?(details: ColorPickerValueChangeDetails) → void

Runs once the drag, key press or typed color that changed the value ends.

Type
(details: ColorPickerValueChangeDetails) → void
Parameters

details – { value: ColorValue; valueAsString: string }

Returns
void
onValueCommit?(value: string, details: ColorPickerValueCommitDetails) → void

Runs once an interaction that changed the value ends: the pointer lifts, a key is pressed, a swatch is picked. For saving.

Type
(value: string, details: ColorPickerValueCommitDetails) → void
Parameters

value – string

details – ColorPickerValueCommitDetails

Returns
void
positioning?object

Where the popup opens against its trigger.

Type
{ gutter?: number; offset?: { mainAxis?: number; crossAxis?: number }; placement?: Placement }
readOnly?boolean

Keeps the parts focusable and the value submitted, but stops changes.

Default
false
required?boolean

Marks it required, with data-required. A color picker always has a value, so it never blocks a form.

space?ColorPickerSpace

The space the parts edit in, which decides their channels: "hsv" has hue, saturation and brightness, "hsl" hue, saturation and lightness, "srgb" red, green and blue, "oklch" lightness, chroma and hue.

Default
"hsv"
unmountOnExit?boolean

Unmounts the popup once it closes. false keeps it mounted. @default true.

Default
true
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-out-of-gamut?string

Present while a drag or a key holds a color outside the gamut. The value is the closest color inside, and the parts move there once the change commits.

data-readonly?string

Present when the picker shows its color but can't change it.

data-required?string

Present when the picker is required.

CSS variableType
--color-picker-colorstring

The color as CSS, inside the gamut. On a swatch item, its own color. Use it to fill a thumb or a swatch.

ColorPickerRootProvider

PropType
valueUseColorPickerReturn

The picker from useColorPicker.

lazyMount?boolean

Kept for the other bases: the popup mounts as it opens.

Default
false
unmountOnExit?boolean

Unmounts the popup once it closes. false keeps it mounted. @default true.

Default
false
class?string

Merged with the part's classes.

ColorPickerLabel

PropType
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

ColorPickerControl

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

PropType
class?string

Merged with the part's classes.

ColorPickerTrigger

<button> data-slot="popover-trigger"

PropType
controller?PopupController<any, PopoverOpenChangeReason, {}, string, PopoverPayloadChangeReason>

Connects a trigger outside the popover, like one per table row, to the popover with this controller.

Type
PopupController<any, PopoverOpenChangeReason, {}, string, PopoverPayloadChangeReason>
disabled?boolean

Stops the trigger from opening the popover. A native button can't be focused or pressed, unless focusableWhenDisabled is set.

Default
false
focusableWhenDisabled?boolean

Keeps a disabled trigger in the tab order with aria-disabled instead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.

Default
false
payload?unknown

Data for the content to render when this trigger opens the popover, like the row it belongs to.

shortcut?string

A keyboard shortcut that presses the trigger, like "mod+i". mod is Command on Apple platforms and Control elsewhere. Sets aria-keyshortcuts.

render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-closed?string

Present while the popover is closed, including while it animates out.

data-disabled?string

Present when the trigger is disabled.

data-open?string

Present while the popover is open. On a trigger, while it's open from that trigger.

ColorPickerTransparencyGrid

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

PropType
class?string

Merged with the part's classes.

ColorPickerContent

<div> data-slot="popover-content"

PropType
align?Align

How the popup lines up with the anchor along that side. start and end follow the reading direction. How the popover lines up with the trigger along that side.

Default
"center"
alignOffset?number

Shift along the anchor, in pixels. Shift along the trigger, in pixels.

Default
0
anchor?string | Anchor | null

Positions the popup against this instead of its trigger: an element, a CSS selector, a point like { x, y }, or anything with getBoundingClientRect(). It's read on every check, so it can move. A controller's open({ anchor }) wins for that open.

Type
string | Anchor | null
arrowPadding?number

Space to keep between the arrow and the popup's corners, in pixels.

Default
6
collisionPadding?number

Space to keep from the viewport edges, in pixels.

Default
8
container?DocumentFragment | Element | null

Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.

Type
DocumentFragment | Element | null
finalFocus?PopupFocusTarget

Where focus goes when the popover closes while focus is inside it.

Default
"trigger"
initialFocus?PopoverInitialFocus

Where focus goes when the popover opens. Opening on hover never moves focus, and opening with touch focuses the popover itself so no on-screen keyboard appears, unless this is set to something other than "auto".

Default
"auto"
inline?boolean

Renders the popover where it is in the page instead of above it, inside its parent's layout and stacking, and leaves placing it to your CSS: side, align and the offsets don't apply.

Default
false
keepMounted?boolean

Whether the popover stays in the page, hidden, while closed. Its content keeps its state between opens.

Default
false
side?Side

Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the trigger the popover opens on.

Default
"bottom"
sideOffset?number

Gap between the anchor and the popup, in pixels. Gap between the trigger and the popover, in pixels.

Default
4
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-align"start" | "center" | "end"

How the popover lines up with its trigger.

Type
"start" | "center" | "end"
data-closed?string

Present while the popover is closed, including while it animates out.

data-ending-style?string

Present while the popover animates out. Style the state you animate to.

data-open?string

Present while the popover is open. On a trigger, while it's open from that trigger.

data-presentation"popover" | "sheet"

How the popover presents this time it's open.

Type
"popover" | "sheet"
data-side"top" | "right" | "bottom" | "left"

Where the popover ended up, after flipping away from edges. Set on the arrow too.

Type
"top" | "right" | "bottom" | "left"
data-starting-style?string

Present for the first frame. Style the state you animate from.

CSS variableType
--anchor-heightstring

Height of the anchor.

--anchor-widthstring

Width of the anchor, usually the trigger. Use it to match widths.

--arrow-offsetstring

Where the anchor's center falls along the popup's edge, kept arrowPadding from the corners. Position a ::before arrow with it.

--available-heightstring

Space between the anchor and the viewport edge. Use it for max-height. Not inherited, so a child that needs it copies it on the popup, like [--list-height:var(--available-height)], and reads max-h-(--list-height). The first popup registers both names for the whole page with CSS.registerProperty, so they don't inherit anywhere. A page that needs them to inherit calls it first, with inherits: true. An @property rule can't, since a registration in script wins.

--available-widthstring

Space beside the popup, up to the viewport edge. Not inherited either.

--drawer-dimstring

While it presents as a sheet: how dim the page behind is, from 0 to 1. The backdrop's opacity follows it.

--drawer-expandstring

While it presents as a sheet: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.

--drawer-progressstring

While it presents as a sheet: how far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.

--drawer-stackstring

While it presents as a sheet: how many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.

--sheet-backdropstring

Set it yourself: the color the page dims to while it presents as a sheet. Black at 0.2 by default.

--transform-originstring

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

ColorPickerView

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

PropType
formatColorFormat

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

class?string

Merged with the part's classes.

ColorPickerSlider

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

PropType
channel?ColorChannel

The channel the slider edits, like "hue" or "alpha".

Default
hue, or blue in sRGB
orientation?"horizontal" | "vertical"

The slider's axis. Vertical sliders grow upward.

Type
"horizontal" | "vertical"
Default
"horizontal"
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-channel"hue" | "saturation" | "brightness" | "lightness" | "chroma" | "red" | "green" | "blue" | "alpha"

The channel the part edits.

Type
"hue" | "saturation" | "brightness" | "lightness" | "chroma" | "red" | "green" | "blue" | "alpha"
data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-orientation"horizontal" | "vertical"

The slider's axis.

Type
"horizontal" | "vertical"
data-out-of-gamut?string

Present while a drag or a key holds a color outside the gamut. The value is the closest color inside, and the parts move there once the change commits.

data-readonly?string

Present when the picker shows its color but can't change it.

data-required?string

Present when the picker is required.

CSS variableType
--color-slider-backgroundstring

A gradient through the slider's channel, with the other channels as they are.

ColorPickerEyeDropperTrigger

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

PropType
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-out-of-gamut?string

Present while a drag or a key holds a color outside the gamut. The value is the closest color inside, and the parts move there once the change commits.

data-readonly?string

Present when the picker shows its color but can't change it.

data-required?string

Present when the picker is required.

data-size?string

Mirrors size.

data-unsupported?string

Present when the browser can't pick a color from the screen.

data-variant?string

Mirrors variant.

ColorPickerSwatchGroup

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

PropType
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-out-of-gamut?string

Present while a drag or a key holds a color outside the gamut. The value is the closest color inside, and the parts move there once the change commits.

data-readonly?string

Present when the picker shows its color but can't change it.

data-required?string

Present when the picker is required.

ColorPickerSwatchTrigger

<button> data-slot="color-picker-swatch-item"

PropType
valuestring | ColorValue

The color it picks, as any CSS color or hsba(…).

Type
string | ColorValue
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-readonly?string

Present when the picker shows its color but can't change it.

data-selected?string

Present on the swatch item whose color is the value.

CSS variableType
--color-picker-colorstring

The color as CSS, inside the gamut. On a swatch item, its own color. Use it to fill a thumb or a swatch.

ColorPickerSwatch

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

PropType
respectAlpha?boolean

Fills it with its color's alpha. false shows the color opaque. @default true.

Default
true
value?string | ColorValue

The color it shows. Without one, the picker's value, named for screen readers.

Type
string | ColorValue
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-out-of-gamut?string

Present while a drag or a key holds a color outside the gamut. The value is the closest color inside, and the parts move there once the change commits.

data-readonly?string

Present when the picker shows its color but can't change it.

data-required?string

Present when the picker is required.

CSS variableType
--color-picker-colorstring

The color as CSS, inside the gamut. On a swatch item, its own color. Use it to fill a thumb or a swatch.

ColorPickerSwatchIndicator

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

PropType
class?string

Merged with the part's classes.

ColorPickerValue

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

PropType
format?ColorStringFormat

The format it writes the value in. The picker's own by default.

class?string

Merged with the part's classes.

ColorPickerValueSwatch

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

PropType
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-out-of-gamut?string

Present while a drag or a key holds a color outside the gamut. The value is the closest color inside, and the parts move there once the change commits.

data-readonly?string

Present when the picker shows its color but can't change it.

data-required?string

Present when the picker is required.

CSS variableType
--color-picker-colorstring

The color as CSS, inside the gamut. On a swatch item, its own color. Use it to fill a thumb or a swatch.

ColorPickerArea

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

PropType
showDots?boolean

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

Default
false
xChannel?ColorChannel

The channel across, left to right.

yChannel?ColorChannel

The channel up, bottom to top.

render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-out-of-gamut?string

Present while a drag or a key holds a color outside the gamut. The value is the closest color inside, and the parts move there once the change commits.

data-readonly?string

Present when the picker shows its color but can't change it.

data-required?string

Present when the picker is required.

CSS variableType
--color-area-backgroundstring

Gradients that draw the area, when its channels are saturation and brightness or lightness. Unset for others, which a canvas paints.

ColorPickerAreaThumb

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

PropType
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-area-thumb?string

Present on the area's thumb, which a press on the area moves and focuses.

data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-out-of-gamut?string

Present while a drag or a key holds a color outside the gamut. The value is the closest color inside, and the parts move there once the change commits.

data-readonly?string

Present when the picker shows its color but can't change it.

data-required?string

Present when the picker is required.

CSS variableType
--area-xstring

Where the thumb is across the area, from 0 to 1.

--area-ystring

Where the thumb is up the area, from 0 at the bottom to 1 at the top.

ColorPickerInput

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

PropType
channel?ColorChannel | "hex" | "css"

What it edits: hex reads any CSS color as text; a channel, like red or alpha, is a number in the units people read it in.

Type
ColorChannel | "hex" | "css"
Default
"hex"
render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

AttributeType
data-channel"hue" | "saturation" | "brightness" | "lightness" | "chroma" | "red" | "green" | "blue" | "alpha"

The channel the part edits.

Type
"hue" | "saturation" | "brightness" | "lightness" | "chroma" | "red" | "green" | "blue" | "alpha"
data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-out-of-gamut?string

Present while a drag or a key holds a color outside the gamut. The value is the closest color inside, and the parts move there once the change commits.

data-readonly?string

Present when the picker shows its color but can't change it.

data-required?string

Present when the picker is required.

ColorPickerSwatchPreview

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

PropType
class?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the picker is disabled, by its own prop or a <fieldset>.

data-out-of-gamut?string

Present while a drag or a key holds a color outside the gamut. The value is the closest color inside, and the parts move there once the change commits.

data-readonly?string

Present when the picker shows its color but can't change it.

data-required?string

Present when the picker is required.

CSS variableType
--color-picker-colorstring

The color as CSS, inside the gamut. On a swatch item, its own color. Use it to fill a thumb or a swatch.

useColorPicker

PropType
open?boolean

Whether the popup is open. Pass it to control the popup. Two-way with bind:open.

defaultOpen?boolean

Whether the popup starts open, when uncontrolled.

onOpenChange?(details: ColorPickerOpenChangeDetails) → void

Called when it opens or closes.

Type
(details: ColorPickerOpenChangeDetails) → void
Parameters

details – { open: boolean }

Returns
void
value?string | ColorValue

The ker's value. Two-way with bind:value.

Type
string | ColorValue
defaultValue?string | ColorValue

The value it starts with, when you don't control value.

Type
string | ColorValue
onValueChange?(details: ColorPickerValueChangeDetails) → void

Runs on every step of a drag or a key.

Type
(details: ColorPickerValueChangeDetails) → void
Parameters

details – { value: ColorValue; valueAsString: string }

Returns
void
closeOnSelect?boolean

Closes the popup once a swatch is picked. @default false.

controller?{ getValue: () → string; setValue: (value: string, options?: ColorPickerChangeOptions) → boolean; focus: () → void; }

Sets the value from anywhere. Create one with createColorPickerController().

Type
{ getValue: () → string; setValue: (value: string, options?: ColorPickerChangeOptions) → boolean; focus: () → void; }
debug?boolean

Logs every state change with its reason to the console, in development builds.

disabled?boolean

Disables every part: they can't be focused or changed, and the value isn't submitted.

form?string

The id of a form to belong to, when it isn't inside that form.

format?ColorFormat

How valueAsString is written, and the channels the sliders and inputs edit. An area edits saturation and brightness in hsba (and without a format), saturation and lightness in hsla, red and green in rgba.

Default
"rgba"
gamut?false | ColorGamut

The colors the value can hold. A drag can go past the edge, and the value is the closest color inside it; once the drag ends, the picker moves there too. "p3" allows wide-gamut screens' colors, and false any color.

Type
false | ColorGamut
Default
"srgb"
inline?boolean

Lays the parts out in place, without a popup.

invalid?boolean

Marks the picker and its inputs invalid.

lazyMount?boolean

Kept for the other bases: the popup mounts as it opens.

name?string

The name the value submits under. Without one, the picker submits nothing.

onFocusOutside?(event: ColorPickerInteractOutsideEvent) → void

Called when focus moves outside it. Prevent its default to keep it open.

Type
(event: ColorPickerInteractOutsideEvent) → void
Parameters

event – ColorPickerInteractOutsideEvent

Returns
void
onInteractOutside?(event: ColorPickerInteractOutsideEvent) → void

Runs before a press or focus outside closes the popup. event.preventDefault() keeps it open.

Type
(event: ColorPickerInteractOutsideEvent) → void
Parameters

event – ColorPickerInteractOutsideEvent

Returns
void
onPointerDownOutside?(event: ColorPickerInteractOutsideEvent) → void

Called when a pointer goes down outside it. Prevent its default to keep it open.

Type
(event: ColorPickerInteractOutsideEvent) → void
Parameters

event – ColorPickerInteractOutsideEvent

Returns
void
onValueChangeEnd?(details: ColorPickerValueChangeDetails) → void

Runs once the drag, key press or typed color that changed the value ends.

Type
(details: ColorPickerValueChangeDetails) → void
Parameters

details – { value: ColorValue; valueAsString: string }

Returns
void
onValueCommit?(value: string, details: ColorPickerValueCommitDetails) → void

Runs once an interaction that changed the value ends: the pointer lifts, a key is pressed, a swatch is picked. For saving.

Type
(value: string, details: ColorPickerValueCommitDetails) → void
Parameters

value – string

details – ColorPickerValueCommitDetails

Returns
void
positioning?object

Where the popup opens against its trigger.

Type
{ gutter?: number; offset?: { mainAxis?: number; crossAxis?: number }; placement?: Placement }
readOnly?boolean

Keeps the parts focusable and the value submitted, but stops changes.

required?boolean

Marks it required, with data-required. A color picker always has a value, so it never blocks a form.

space?ColorPickerSpace

The space the parts edit in, which decides their channels: "hsv" has hue, saturation and brightness, "hsl" hue, saturation and lightness, "srgb" red, green and blue, "oklch" lightness, chroma and hue.

Default
"hsv"
unmountOnExit?boolean

Unmounts the popup once it closes. false keeps it mounted. @default true.

render?Snippet<[{ props, state, children }]>

Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.

Type
Snippet<[{ props, state, children }]>
class?string

Merged with the part's classes.

ColorPickerContext