Skip to content

Checkbox

A control that allows the user to toggle between checked and not checked.

Demo

checkbox.html
<div x-init x-checkbox.checked>
<button x-checkbox:indicator>
<svg></svg>
</button>
<label x-checkbox:label>Accept terms and conditions</label>
</div>

Features

  • Full keyboard navigation.

Anatomy

<div x-init x-checkbox>
<button x-checkbox:indicator></button>
<label x-checkbox:label></label>
</div>

Directives

x-checkbox

Required

The root element for the checkbox.

ModifierDescription
.checkedChecks the checkbox by default
EventDescriptiondetail
checkbox:changeWhether the checkbox is checked or unchecked.{ checked: boolean }
Data AttributeValues
[data-state]checked | unchecked

x-checkbox:indicator

Required

Visual indicator for the checkbox.

EventDescriptiondetail
checkbox:changeWhether the checkbox is checked or unchecked.{ checked: boolean }
Data AttributeValues
[data-state]checked | unchecked

x-checkbox:label

Required

Text label for the checkbox.

Data AttributeValues
[data-state]checked | unchecked