Skip to content

Color Field

An input for CSS colors or a single color channel.

Anatomy

  • #default: Optional content after the input. Receives value, draft, and isInvalid.

Usage

CSS color text

Enter a CSS color. The swatch shows the last valid value while you type.

Required field and form reset

Enter a valid color to submit. Reset clears the field.

Not submitted

Examples

Required field and form reset

Enter a valid color to submit the form. This example submits LCH text. Reset clears the field.

vue
<Dialog
  :ui="{
    overlay: 'fixed inset-0 bg-black/50 backdrop-blur-sm',
    content: 'bg-white rounded-xl shadow-xl w-full max-w-md',
    header: 'flex items-center justify-between p-6 border-b',
    body: 'p-6',
    footer: 'flex justify-end gap-2 p-6 border-t',
  }"
>

See the live demo's code for fieldUi and the submit handler.

Formats

Set format to choose the returned color string. It does not change which colors you can enter or which channels you edit. See supported formats. Changing the format keeps opacity and emits value-change with reason format. HEX uses eight digits for transparent colors; hexa uses eight digits for all colors.

HEX and RGB can lose colors outside sRGB. The control keeps the original color until you replace the model or enter a new value. Area and slider previews use sRGB. See precision and gamut for details.

Use a color value such as #56d799 or oklch(0.65 0.2 250). CSS variables, currentColor, and relative color expressions are not supported.

Behavior

The field starts empty. While you type an incomplete value such as # or oklch(, the model keeps its last valid color. The field shows validation state after you leave it. Invalid drafts block form submission. Press Escape to restore the last valid color.

Valid input updates v-model as you type. Leaving the input or pressing Enter emits value-commit. The visible input handles browser validation; a hidden input submits the color in the chosen format. Use ui.input to style the text box; class styles its wrapper.

Set channel to edit one number, such as hue or opacity. Set colorSpace to choose its units. See useColor channels for the ranges and steps.

API Reference

Props

PropTypeDefaultPurpose
modelValuestring""Selected CSS color. Bind with v-model.
formatColorFormat"hex"Format for the returned and submitted color string.
id, namestringFrom FieldInput ID and form field name.
required, disabled, readOnly, invalidbooleanfalseNative validation and interaction states; disabled/required also inherit from Field.
ariaLabel, ariaLabelledby, ariaDescribedbystringFrom Field where applicableAccessible naming and description.
uiComponent UI object-Classes for the named parts below.
channelColorChannel-Omit for a complete CSS color; provide for a numeric channel.
colorSpaceColorSpace"hsb"Space used by numeric channel editing.
stepnumberChannel defaultIncrement for arrow/wheel actions.
localestringRuntime localeNumber formatting and decimal separator for channel editing.
disableWheelChangebooleantrueWheel adjustment is opt-in and only applies while focused.
placeholderstring-Empty input hint.

Emits

EventPayloadMeaning
update:modelValueSelected colorVue model update.
value-change(value, details)Runs before a change. Use details.cancel() to stop it. Includes reason and the native event when available.
value-commit(value, details)Runs when an interaction ends. Canceling it does not undo the value change.

Slots

  • #default: Optional content after the input. Receives value, draft, and isInvalid.

UI Options

KeyElement
rootWrapper; direct class styles this wrapper
inputVisible input; use ui.input for borders and typography
hiddenInputNormalized form value

Styling Hooks

UI keyCSS classData attributes / semantics
rootakaza-color-fieldShared form flags
inputakaza-color-field-inputShared form flags; native input attributes
hiddenInputakaza-color-field-hidden-inputname, value, disabled

Form state attributes: data-akaza-disabled, data-akaza-readonly, data-akaza-invalid, data-akaza-focused, data-akaza-touched, data-akaza-dirty, data-akaza-filled, and data-akaza-out-of-gamut. Each appears only when true.

Use class or ui.root to style the root. Use the other ui keys for inner parts. Set sizes, borders, and colors in your own styles.

Keyboard

KeyBehavior
ArrowUp / ArrowDownIncrement/decrement the channel. In whole-color mode, increment/decrement the RGB HEX integer.
PageUp / PageDownAdjust by ten steps.
Home / EndUse channel minimum/maximum; whole-color text retains normal caret behavior.
EnterCommit a valid draft without suppressing normal form submission.
EscapeRestore a pending draft without committing it. With nothing to restore, allow the parent popup to handle Escape.

Parity Notes

ColorField combines Reka's root and input parts in one component. Use ui.input to style the input. The supplied Base UI reference has no color field component.

Edit this page on GitHub ↗