Color picker

Pick a color: an inline picker (saturation area, hue, opacity, swatches) and a text field with the picker in a dropdown and an eyedropper. Pointer and keyboard; form-associated; hex, rgb or hsl, with or without alpha.

Source on GitHub

Picker
#7c3aedDrag the area or the hue, or use the arrow keys.
Formats and opacity
format="rgba"
format="hsla"
format="hexa"
Swatches
picker + swatches
swatches-only
Color input
In a form
bug
Save labelReset
Code

API

For AI agents: this API as Markdown, or every component in llms-full.txt.

<ray-color-picker>

Keyboard: arrows move the area's thumb (saturation, brightness) or a slider's; Shift for 10× steps; Home/End on the sliders. The alpha slider shows when format has alpha.

PropertyAttributeTypeDefaultDescription
valuevaluestringThe color, written in format. Any color is accepted and rewritten in format. The value attribute is the initial value (restored on form reset).
formatformat reflectsstringhexHow value is written: hex, hexa, rgb, rgba, hsl or hsla. Formats ending in a show the opacity slider.
swatchesswatchesstringPreset colors below the picker: an array, or a comma-separated list in the attribute (commas inside rgb()/hsl() are kept).
swatchesPerRowswatches-per-rownumber7Swatches in each row.
swatchesOnlyswatches-only reflectsbooleanOnly the swatches: no area nor sliders.
sizesize reflectsxs | sm | md | lg | xlmdWidth of the picker and size of its thumbs.
fullWidthfull-width reflectsbooleanTakes the width of its container.
namename reflectsstringForm field name.
disableddisabled reflectsbooleanNot interactive.
labellabelstringAccessible name of the whole picker.
EventDescription
inputThe color moved (every step of a drag).
changeThe color settled: pointer released, a key pressed or a swatch chosen (read value).
PartDescription
saturationThe saturation/brightness area.
hueThe hue slider.
alphaThe opacity slider.
previewThe current color.
swatchesThe swatches' grid.

<ray-color-input>

Type any CSS color (it becomes the value as soon as it is valid; invalid text goes back to the value on blur), or open the picker with a click or ArrowDown. The eyedropper shows only where the browser has the EyeDropper API.

PropertyAttributeTypeDefaultDescription
valuevaluestringThe color, written in format. The value attribute is the initial value (restored on form reset).
formatformat reflectsstringhexHow value is written: hex, hexa, rgb, rgba, hsl or hsla.
swatchesswatchesstringPreset colors in the dropdown (an array, or a comma-separated list).
swatchesPerRowswatches-per-rownumber7Swatches in each row.
placeholderplaceholderstringShown while empty.
hideEyedropperhide-eyedropper reflectsbooleanHides the eyedropper button.
openopen reflectsbooleanThe dropdown is shown.
namename reflectsstringForm field name.
labellabelstringLabel above the field.
descriptiondescriptionstringHelp text.
errorerrorstringError message; marks the field invalid.
requiredrequired reflectsbooleanMust have a color.
disableddisabled reflectsbooleanNot interactive.
sizesize reflectsxs | sm | md | lg | xlsmField height and font size.
radiusradius reflectsstringCorner radius: xs…xl or a CSS length.
variantvariant reflectsdefault | filled | unstyleddefaultVisual style of the field.
descriptionPositiondescription-position reflectsabove | belowaboveWhere the description goes.
EventDescription
inputThe color changed (typing a valid color, or moving the picker).
changeThe color settled (picker released, a swatch, the eyedropper, or the field left with a new color).
ray-openThe dropdown opened.
ray-closeThe dropdown closed.
PartDescription
inputThe text field.
previewThe swatch of the current color.
eyedropperThe eyedropper button.
dropdownThe dropdown with the picker.

Texts

What it writes itself, in English; setStrings() translates them (Getting started: Languages).

KeyEnglish
color-picker.saturationSaturation and brightness
color-picker.saturation-valueSaturation {saturation}%, brightness {brightness}%
color-picker.hueHue
color-picker.hue-value{hue} degrees
color-picker.opacityOpacity
color-picker.swatchesSwatches
color-picker.eyedropperPick a color from the screen
color-picker.dropdownChoose a color