Skip to content

React Color Picker

A glass React color picker with a saturation area, hue and opacity sliders, typed hex, RGB and HSL values, swatches and the screen eyedropper.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/color-picker.json

Choose your accent

HexRGBHSL
#6d4aff

Picker

Drag the area or use the arrow keys on it (Shift for bigger steps). The value is always emitted as hex.

HexRGBHSL
#6d4aff

Files to copy

7 folders · 12 files · 4 packages
From theme/src/
  • components/color-picker/
  • components/date-picker/picker-surface.tsx
  • components/status-icons/
  • hooks/{use-controllable.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, field-size.ts, form.ts, math.ts, popup-motion.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/color-picker.jsonRegistry item: color-picker. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Color field

A hex field with a swatch that opens the picker in a glass popover (a bottom sheet on phones). Type a hex straight into the field, or submit it with name.

Used for buttons and links.

Hex only, no opacity

Trim it down: one format, no opacity, no swatches.

ColorPicker props

PropTypeDefaultDescription
aria-describedbystringNoneIds of elements that describe the field, merged with the control's own description and error ids.
aria-invalidboolean | "true" | "false"NoneMarks the field as invalid (also set automatically when error is shown).
onBlurFocusEventHandler<HTMLElement>NoneCalled when focus leaves the control (not when it moves between the control's own parts).
namestringNoneField name, used for native form submission and by form libraries.
disabledbooleanfalseDisables every control in the picker.
valuestringNoneThe colour (controlled): any hex, rgb() or hsl() string.
defaultValuestringa violetThe colour on mount (uncontrolled).
onValueChange((value: string) => void)NoneCalled while the colour changes (dragging, typing), with hex.
onValueCommit((value: string) => void)NoneCalled once a change is done (pointer up, Enter, blur), with hex.
alphabooleantrueShow the opacity slider and channel.
formatColorFormatNoneThe channel format shown under the sliders (controlled): "hex", "rgb" or "hsl".
defaultFormatColorFormat"hex"The channel format on mount (uncontrolled).
onFormatChange((format: ColorFormat) => void)NoneCalled with the new format when the format switch changes.
formatsColorFormat[]["hex", "rgb", "hsl"]Formats offered by the switch.
swatchesColorSwatch[][]Sets the preset colours, as strings or { value, label }.
eyeDropperbooleantrueOffer the screen eyedropper (only shown where window.EyeDropper exists).
copyButtonbooleantrueShow the copy button.
variant"card" | "plain""card""card": its own glass card. "plain": no surface, for popovers and your own layouts.
aria-labelstringNoneAccessible name of the whole picker group.
labelsPartial<ColorPickerLabels>defaultColorPickerLabelsEvery other string, for translation: labels={{ area: "…" }}; omitted keys keep the English of defaultColorPickerLabels. All 25 keys of ColorPickerLabels are listed in the key table under the props table.
classNamestringNoneAdds extra classes to the outer element.
ColorPickerLabels keys and English defaults (25)
Pass any key in labels; the rest keep the defaults of defaultColorPickerLabels.
KeyEnglish default
areaSaturation and brightness
areaValue(s, v) => `Saturation ${s}%, brightness ${v}%`
hueHue
hueValue(h) => `${h} degrees`
alphaOpacity
alphaValue(a) => `${a}%`
formatColour format
formats{ hex: "Hex", rgb: "RGB", hsl: "HSL" }
hexHex colour
redRed
greenGreen
blueBlue
hueShortHue
saturationSaturation
lightnessLightness
opacityOpacity
captions{ hex: "Hex", r: "R", g: "G", b: "B", h: "H", s: "S", l: "L", a: "A" }
eyeDropperPick a colour from the screen
copyCopy colour
copied(value) => `Copied ${value}`
swatchesSwatches
openOpen colour picker
pickerTitleChoose a colour
closeClose
swatch(value) => value

ColorField props

PropTypeDefaultDescription
defaultValuestring"#7c5cff"The colour on mount (uncontrolled).
aria-describedbystringNoneIds of elements that describe the field, merged with the control's own description and error ids.
aria-invalidboolean | "true" | "false"NoneMarks the field as invalid (also set automatically when error is shown).
formatColorFormatNoneThe channel format shown under the sliders (controlled): "hex", "rgb" or "hsl".
disabledbooleanfalseDisables every control in the picker.
valuestringNoneThe colour (controlled): any hex, rgb() or hsl() string.
onValueChange((value: string) => void)NoneCalled while the colour changes (dragging, typing), with hex.
onValueCommit((value: string) => void)NoneCalled once a change is done (pointer up, Enter, blur), with hex.
alphabooleantrueShow the opacity slider and channel.
defaultFormatColorFormat"hex"The channel format on mount (uncontrolled).
onFormatChange((format: ColorFormat) => void)NoneCalled with the new format when the format switch changes.
formatsColorFormat[]["hex", "rgb", "hsl"]Formats offered by the switch.
swatchesColorSwatch[]NoneSets the preset colours, as strings or { value, label }.
eyeDropperbooleantrueOffer the screen eyedropper (only shown where window.EyeDropper exists).
copyButtonbooleantrueShow the copy button.
labelsPartial<ColorPickerLabels>defaultColorPickerLabelsEvery other string, for translation: labels={{ area: "…" }}; omitted keys keep the English of defaultColorPickerLabels. All 25 keys of ColorPickerLabels are listed in the key table under the props table.
onBlurFocusEventHandler<HTMLElement>NoneCalled when focus leaves the control (not when it moves between the control's own parts).
namestringNoneSubmits the hex value with a form.
requiredbooleanNoneMarks the field as required.
sizeFieldSize"md"Height, consistent across every form control: "sm" 32px, "md" 40px, "lg" 48px (sm and md are 44px on touch screens), the same scale as Button.
labelReactNodeNoneVisible label above the field. Without one, pass aria-label.
descriptionReactNodeNoneHelper text under the field; replaced by error when there is one.
errorReactNodeNoneShows an error message under the field.
idstringNoneSets the id of the text input.
aria-labelstringNoneAccessible name of the text input when there is no label.
placeholderstring"#000000"Sets the placeholder of the text input.
classNamestringNoneAdds extra classes to the outer wrapper.

Keyboard

KeysAction
Arrow Left/Arrow RightColor area: change saturation. Hue and opacity sliders: change the value.
Arrow Up/Arrow DownColor area: change brightness (Shift for steps of 10).
Page Up/Page DownChange brightness (or slider value) by 10.
Home/EndSaturation 0 / 100 in the area; the ends of a slider.
Enter/Space/Arrow DownColorField: open the picker from the swatch button. Escape closes it.

Accessibility

  • The color area is a 2-D slider; the area, hue and opacity sliders and each channel input have a name and a spoken value ("Saturation 64%, brightness 100%").
  • In ColorField, type a hex value and press Enter or leave the field to apply it (Escape discards); description and error are linked with aria-describedby.
  • Copying announces the copied value politely. The color graphics opt out of forced colors (they are content, like an image); the controls around them keep system colors.

All exports on this page

  • ColorField — A hex text field with a swatch button that opens the full ColorPicker (a glass popover from 640px up, a bottom sheet on phones).
  • ColorPicker — A colour picker: a saturation / brightness area, hue and opacity sliders, typed values (hex, RGB or HSL), swatches, copy.
  • defaultColorPickerLabels — The English strings of ColorPicker.

When to use the color picker

  • Use it as a hex, RGB and HSL color picker in a theme editor or brand settings screen where people tune an accent color with the saturation and brightness area, a hue slider and an opacity slider, then copy the result.
  • Use it for design-tool style inputs such as a highlight color for a note, a chart series color or a label color, where presets via the swatches prop give one-click choices beside free selection.
  • Use ColorField when the picker belongs in a form: it shows a swatch plus a hex text field and opens the picker as a popover from 640px up, or as a bottom drawer on phones.
  • Skip it when users only choose from five or six fixed brand colors; a RadioGroup with swatch cards or a SegmentedControl is simpler and needs no continuous color space or typed values.
  • Pair it with Popover for custom trigger layouts, the label, description and error props of ColorField for the name and message, and Slider or Switch next to it for related theme settings like contrast.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .