The colorpicker input allows for advanced color selection — including alpha channel support. It supports colors in Hex, HSLA and RGBA formats and can be configured to provide a preset list of colors.

Most importantly, unlike the native color input, the colorpicker provides a consistent, predictable, and accessible user experience across browsers and operating systems.

The colorpicker input is fully keyboard navigable and ships with accessible markup.

Basic example

Load live example

Color formats

Supported formats

The colorpicker supports formats in Hex, HSLA and RGBA formats. You can set your desired format with the format prop and color values from the colorpicker will be returned in that format. Your chosen format will also be the default setting for the input field(s) which show up in the colorpicker panel.

Load live example

Value format

There may be times where you wish to show one format to users as a default but return a different format. You can use the value-format prop to specify a return value format independent of the format prop.

Load live example

Swatches

Swatches are provided using the options prop and use the same options API as the select, dropdown, autocomplete and taglist inputs from FormKit.

Simple swatches

Here is a simple set of swatches using the options prop and providing it with a flat array of color values. Your provided values can be in any supported color format (Hex, HSLA, and RGBA) and will be automatically converted to the colorpickers speficied format which defaults to Hex.

Load live example

Grouped swatches

The colorpicker also supports grouped options. This allows you to create sets of swatches within the color picker grouped under a common heading.

Load live example

Swatch-only

You can create a "swatch-only" color-picker by using the panel-controls and panel-format props and setting them to false.

When showing only swatches in pop-over mode (the default) adding the close-on-select prop will close the pop-over when a swatch is selected.

Load live example

Inputting by swatch name

If your provided swatches via the options prop have labels then you can call node.input() with a swatch name and the associated color will be set for you.

Load live example

Eyedropper

The colorpicker input supports the browser-native EyeDropper API. If the EyeDropper is supported in your browser and you have not disabled the EyeDropper by setting the eye-dropper prop to false then you will see an eyedropper button to the right of the hue and alpha sliders.

Load live example

Pasting values

By default a colorpicker input will allow the pasting of any valid color values while user focus is anywhere in the input. Values will be converted immediately to your desired format.

You can disable the ability to paste a value by setting the allow-paste prop to false.

Load live example

Props & Attributes

PropTypeDefaultDescription
formatstringhexThe format that the colorpicker input should show in the input preview and be the default setting for the picker panel input. Can be set to hex, hsla or rgba.
value-formatstringundefinedThe format that should be returned from the colorpicker input regardless of the displayed format. If not specified the value of the format prop will be used.
panel-controlsbooleantrueUsed to control the display of the Lightness/Saturation gradient and the Hue and Alpha sliders.
panel-formatbooleantrueUsed to control whether the display of the color input fields and format switcher button.
eye-dropperbooleantrueUsed to control the display of the eye-dropper control. Requires a browser that supports the EyeDropper API. If enabled in an unsupported browser the control will behave as if set to false.
inlinebooleanfalseWhen set to true the `colorpicker` will render its panel as an inline element rather than as a pop-over.
optionsArray/Object[]An object of value/label pairs or an array of strings, or an array of objects that must contain a label and value property. Supports grouped options via an array of objects that contain group and options keys where options is a nested options definition. Grouping is only supported at one level of depth.
show-valuebooleantrueUsed to control the display of the current color value in the input preview. Uses the format prop to determine which value to display.
close-on-selectbooleanfalseWhen set to true the colorpicker panel will close when a preset swatch option is chosen.
allow-pastebooleantrueAllows pasting any valid color string of Hex, HSLA, or RGBA format into a colorpicker that contains the user's focus. The pasted string will immediately be set as the value of the colorpicker and converted to the desired format.
popoverbooleanfalseRenders the input's UI panel using the browser Popover API.
Show Universal props
configObject{}Configuration options to provide to the input’s node and any descendent node of this input.
delayNumber20Number of milliseconds to debounce an input’s value before the commit hook is dispatched.
dirtyBehaviorstringtouchedDetermines how the "dirty" flag of this input is set. Can be set to touched or comparetouched (the default) is more performant, but will not detect when the form is once again matching its initial state.
errorsArray[]Array of strings to show as error messages on this field.
helpString''Text for help text associated with the input.
idStringinput_{n}The unique id of the input. Providing an id also allows the input’s node to be globally accessed.
ignoreBooleanfalsePrevents an input from being included in any parent (group, list, form etc). Useful when using inputs for UI instead of actual values.
indexNumberundefinedAllows an input to be inserted at the given index if the parent is a list. If the input’s value is undefined, it inherits the value from that index position. If it has a value it inserts it into the lists’s values at the given index.
labelString''Text for the label element associated with the input.
nameStringinput_{n}The name of the input as identified in the data object. This should be unique within a group of fields.
parentFormKitNodecontextualBy default the parent is a wrapping group, list or form — but this props allows explicit assignment of the parent node.
prefix-iconString''Specifies an icon to put in the prefixIcon section.
preservebooleanfalsePreserves the value of the input on a parent group, list, or form when the input unmounts.
preserve-errorsbooleanfalseBy default errors set on inputs using setErrors are automatically cleared on input, setting this prop to true maintains the error until it is explicitly cleared.
sections-schemaObject{}An object of section keys and schema partial values, where each schema partial is applied to the respective section.
suffix-iconString''Specifies an icon to put in the suffixIcon section.
typeStringtextThe type of input to render from the library.
validationString, Array[]The validation rules to be applied to the input.
validation-visibilityStringblurDetermines when to show an input's failing validation rules. Valid values are blur, dirty, and live.
validation-labelString{label prop}Determines what label to use in validation error messages, by default it uses the label prop if available, otherwise it uses the name prop.
validation-rulesObject{}Additional custom validation rules to make available to the validation prop.
valueAnyundefinedSeeds the initial value of an input and/or its children. Not reactive. Can seed entire groups (forms) and lists..

Sections

You can target a specific section of an input using that section's "key", allowing you to modify that section's classes, HTML (via :sections-schema, or content (via slots)). Read more about sections here.

The colorpicker input's structure changes depending on the existence of the inline prop:

Pop-over structure (default)

Input Preview

View on a larger screen to see this section diagram.

Choose a color
⬛️
#000000
Pick your favorite color.
Color is required

Pop-over panel

View on a larger screen to see this section diagram.

(panelClose is only shown on small touchscreens when in pop-over mode)
🖼️
⬛️
🌈
👻
👁️
#️⃣
0️⃣
0️⃣
0️⃣
0️⃣
0️⃣
0️⃣
1️⃣
🟦
🟥
🟨

Inline structure

View on a larger screen to see this section diagram.

Choose a color
Pick your favorite color.
🖼️
⬛️
🌈
👻
👁️
#️⃣
0️⃣
0️⃣
0️⃣
0️⃣
0️⃣
0️⃣
1️⃣
🟦
🟥
🟨
Color is required
Section-keyDescription
swatchPreviewA wrapping div around the swatch preview canvas element and the displayed color value string.
canvasSwatchPreviewA canvas element that renders the current color selection.
valueStringA span element that contains the current color value string in the format set via the format prop.
panelThe wrapping element for all of the colorpicker controls
panelCloseA prefix seciton of the panel that contains a close button. Only shown on small touchscreen devices where a 'fixed position' treatment is applied.
iconCloseAn element for outputting an icon within the panelClose section.
controlGroupA wrapping element for all of the color control elements within the panel
previewA wrapping element for the current color preview.
canvasPreviewA canvas element that renders the current color selection.
LSA wrapping element for the Lightness/Saturation controls
canvasLSA canvas element that renders the currently avilable colors given the current hue.
controlLSAn element styled as the control for the LS canvas.
hueA wrapping element for the hue controls
canvasHueA canvas element that renders every available hue at 50% lightness.
controlHueAn element styled as the control for the hue canvas.
alphaA wrapping element for the alpha controls
canvasAlphaA canvas element that renders the currently selected color from 0% to 100% opacity.
controlAlphaAn element styled as the control for the alpha canvas.
eyeDropperAn element that acts as a trigger for enabling the browser's EyeDropper API. Only displays in supported browsers.
iconEyeDropperAn element for outputting an icon within the eyeDropper section.
formatFieldA wrapping element that contains all of the color format input fields and the format toggle control. Only the field(s) relevant to the currently selected panel format will be displayed.
colorInputGroupA wrapping element that wraps one or more input fields associated with a given color format.
hexFieldThe input for a hex color format. Supports #RRGGBBAA format although alpha hex values are not required.
rFieldThe input for the R value of an RGBA color format.
gFieldThe input for the G value of an RGBA color format.
bFieldThe input for the B value of an RGBA color format.
hFieldThe input for the H value of an HSLA color format.
sFieldThe input for the S value of an HSLA color format.
lFieldThe input for the L value of an HSLA color format.
aFieldThe input for the A value of an RGBA or HSLA color format.
formatSwitcherAn element that acts as a trigger for changing the currently displayed color format within the colorpicker panel. Has no effect on the format and value-format settings of the input.
iconSwitchAn element for outputting an icon within the formatSwitcher section.
swatchesA wrapping element that contains all available swatches made available via the options prop.
swatchAn element that handles the rendering of each option (or option group) provided by the options prop.
Show Universal section keys
outerThe outermost wrapping element.
wrapperA wrapper around the label and input.
labelThe label of the input.
prefixHas no output by default, but allows content directly before an input element.
prefixIconAn element for outputting an icon before the prefix section.
innerA wrapper around the actual input element.
suffixHas no output by default, but allows content directly after an input element.
suffixIconAn element for outputting an icon after the suffix section.
inputThe input element itself.
helpThe element containing help text.
messagesA wrapper around all the messages.
messageThe element (or many elements) containing a message — most often validation and error messages.

Accessibility

All FormKit inputs are designed with the following accessibility considerations in mind. Help us continually improve accessibility for all by filing accessibility issues here:

Semantic markupAria attributesKeyboard accessibleFocus indicatorsColor contrast with the provided themeAccessible labels, help text, and errors
Section KeyAttributeDefaultDescription
swatchPreviewtabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
rolebuttonIndicates to assistive technologies that this element functions as a button.
aria-valuetextDefines the human-readable text of the value.
panelaria-roledialogWhen layout is set to popover it adds this attribute.
aria-modaltrueWhen layout is set to popover it adds this attribute.
aria-labelProvides an accessible name.
panelClosetabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when panel is closed and 0 when openned.
aria-labelProvides an accessible name.
controlGrouprolegroupIndicates to assistive technologies that this element functions as a group.
canvasLSaria-hiddentrueMakes this element not exposed to the accessibility API.
controlLStabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
rolesliderIndicates to assistive technologies that this element functions as a slider.
aria-valueminDefines the minimum allowed value.
aria-valuemaxDefines the maximum allowed value.
aria-valuetextDefines the human-readable text of the value.
canvasHuearia-hiddentrueMakes this element not exposed to the accessibility API.
controlHuetabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
rolesliderIndicates to assistive technologies that this element functions as a slider.
aria-valueminDefines the minimum allowed value.
aria-valuemaxDefines the maximum allowed value.
aria-valuenowDefines the human-readable text of the value.
canvasAlphaaria-hiddentrueMakes this element not exposed to the accessibility API.
controlAlphatabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
rolesliderIndicates to assistive technologies that this element functions as a slider.
aria-valueminDefines the minimum allowed value.
aria-valuemaxDefines the maximum allowed value.
aria-valuenowDefines the human-readable text of the value.
canvasPreviewaria-hiddentrueMakes this element not exposed to the accessibility API.
canvasSwatchPreviewaria-hiddentrueMakes this element not exposed to the accessibility API.
eyeDroppertabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
rolebuttonIndicates to assistive technologies that this element functions as a button.
colorInputGrouparia-rolegroupIndicates to assistive technologies that this element functions as a group.
hexFieldtabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
forAssociates the label to an input element. Users can click on the label to focus the input or to toggle between states.
rFieldtabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
forAssociates the label to an input element. Users can click on the label to focus the input or to toggle between states.
gFieldtabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
forAssociates the label to an input element. Users can click on the label to focus the input or to toggle between states.
bFieldtabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
forAssociates the label to an input element. Users can click on the label to focus the input or to toggle between states.
aFieldtabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
forAssociates the label to an input element. Users can click on the label to focus the input or to toggle between states.
hFieldtabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
forAssociates the label to an input element. Users can click on the label to focus the input or to toggle between states.
sFieldtabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
forAssociates the label to an input element. Users can click on the label to focus the input or to toggle between states.
lFieldtabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
forAssociates the label to an input element. Users can click on the label to focus the input or to toggle between states.
formatSwitchertabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
rolebuttonIndicates to assistive technologies that this element functions as a button.
aria-labelProvides an accessible name.
swatchtabindex-1 or 0Prioritizes keyboard focus order by setting it to -1 when disabled and 0 when enabled.
rolebuttonIndicates to assistive technologies that this element functions as a button.
aria-labelProvides an accessible name.
Show Universal section key
labellabelforAssociates the label to an input element. Users can click on the label to focus the input or to toggle between states.
inputinputdisabledDisables an HTML element, preventing user interaction and signaling a non-interactive state.
aria-describedbyAssociates an element with a description, aiding screen readers.
aria-requiredAdds this attribute when validation is required.
iconiconforWhenever icon is defined as a label it links it to an input element.

Keyboard Interactions

Keyboard EventDescription
TabMoves the focus to the next focusable input on the page.
Shift + TabMoves the focus to the previous focusable input on the page.