Checkbox

A control for a boolean value. It renders a hidden native input so it can participate in forms. color sets the wash and the checked accent. There is no stroke.

Usage guidelines

  • Accessible name: Form controls must have an accessible name. Wrap the control in a <label>, pair a sibling label with id / for, or use Field.

Anatomy

<UiCheckboxRoot>
  <UiCheckboxIndicator />
</UiCheckboxRoot>

Examples

Labeling a checkbox

An enclosing <label> is the simplest pattern:

<label>
  <UiCheckboxRoot>
    <UiCheckboxIndicator />
  </UiCheckboxRoot>
  Accept terms and conditions
</label>

Rendering as a native button

By default Root renders a <span> so it can sit inside a wrapping label. Prefer a native <button> when the label is a sibling (for / id).

<label :for="id">Enable notifications</label>
<UiCheckboxRoot :id="id" native-button>
  <UiCheckboxIndicator />
</UiCheckboxRoot>

Do not wrap a native button in a <label> — that is invalid HTML.

Form integration

Use Field for the label association and form name:

<UiFieldRoot name="stayLoggedIn">
  <UiFieldLabel>
    <UiCheckboxRoot name="stayLoggedIn">
      <UiCheckboxIndicator />
    </UiCheckboxRoot>
    Stay logged in for 7 days
  </UiFieldLabel>
</UiFieldRoot>

Indeterminate

indeterminate is the mixed state: neither ticked nor unticked. A parent checkbox in a Checkbox Group sets this automatically.

<UiCheckboxRoot :indeterminate="mixed">
  <UiCheckboxIndicator />
</UiCheckboxRoot>

Disabled

disabled ignores presses and sets data-disabled.

<UiCheckboxRoot disabled :default-checked="true">
  <UiCheckboxIndicator />
</UiCheckboxRoot>

Read-only

readOnly keeps the box visible and in the tab order, but it cannot be ticked or unticked.

<UiCheckboxRoot read-only default-checked>
  <UiCheckboxIndicator />
</UiCheckboxRoot>

API reference

Root

The checkbox. Renders a <span> (or <button> when nativeButton) and a hidden <input type="checkbox"> beside it.

PropTypeDefaultDescription
namestring—Name for form submission.
defaultCheckedbooleanfalseUncontrolled initial tick.
checkedboolean—Controlled tick (v-model:checked).
indeterminatebooleanfalseMixed state. Sets data-indeterminate and aria-checked="mixed".
valuestring—Submitted when checked. Identifies the box in a Checkbox Group. When omitted, a checked box submits "on".
formstring—Associates the hidden input with a form id.
nativeButtonbooleanfalseRender a <button type="button"> instead of a span. Use with a sibling label.
parentbooleanfalseControls every child in a Checkbox Group.
uncheckedValuestring—Submitted when unchecked. By default unchecked boxes submit nothing.
disabledbooleanfalseIgnore interaction.
readOnlybooleanfalseVisible but not togglable.
requiredbooleanfalseRequired for form submission.
idstring—Id of the hidden input (for sibling labels).
EventTypeDescription
@update:checked(checked: boolean) => voidEmitted when the box is ticked or unticked.
AttributeDescription
data-checkedPresent when ticked.
data-uncheckedPresent when not ticked.
data-indeterminatePresent when mixed.
data-disabledPresent when disabled.
data-readonlyPresent when read-only.
data-requiredPresent when required.
data-validPresent when valid (inside Field).
data-invalidPresent when invalid (inside Field).
data-dirtyPresent when the value changed (inside Field).
data-touchedPresent when blurred after focus (inside Field).
data-filledPresent when checked (inside Field).
data-focusedPresent when focused.

Indicator

Shows whether the box is ticked (or mixed). Renders a <span>. Enter and leave use data-starting-style / data-ending-style.

PropTypeDefaultDescription
keepMountedbooleanfalseKeep the indicator in the DOM while unchecked.
AttributeDescription
data-checkedPresent when ticked.
data-uncheckedPresent when not ticked.
data-indeterminatePresent when mixed.
data-disabledPresent when the checkbox is disabled.
data-readonlyPresent when the checkbox is read-only.
data-requiredPresent when the checkbox is required.
data-validPresent when valid (inside Field).
data-invalidPresent when invalid (inside Field).
data-dirtyPresent when the value changed (inside Field).
data-touchedPresent when blurred after focus (inside Field).
data-filledPresent when checked (inside Field).
data-focusedPresent when focused.
data-starting-stylePresent while animating in.
data-ending-stylePresent while animating out.