Checkbox
A form control for binary choices or multi-select lists. Supports checked, unchecked, and indeterminate states with full keyboard and screen-reader support.
Basic Usage
States
- Unchecked
- Checked
- Indeterminate
- Disabled
- Disabled and checked
Every state here is one a prop sets. Hover, focus and active are deliberately absent: no stylesheet can put an element into a pseudo-class, so a picture of one would show a state drawn by the page rather than by the component.
Sizes
Three sizes scale the box and its checkmark together — sm, md (default), and lg. They line up with the matching size on Radio and Toggle so a form mixing the controls stays visually consistent. At every size the box stands on the middle of the first line of its label, and a label that wraps keeps its first line beside the box.
Card Variant
variant="card" turns the whole control into a bordered, fully-clickable card that highlights when checked — the canonical "selectable option" pattern for feature toggles and multi-select grids. The card reacts to its own input via CSS :has(), so it needs no JavaScript.
Inside a card, the hint stands under the name as the option's description, and the trailing slot takes what belongs at the end of the row: a price, a logo or an image. Neither becomes part of the checkbox's name, which stays the label. A screen reader reads the hint as the checkbox's description, and what trailing holds as text of the page:
The hint of a card stays in the card when the checkbox shows an error, which stands under the card, and the checkbox is described by both.
With Hint
With Error
Accept the terms to continue.
Errors from Laravel's validation bag are shown automatically when name matches a field, also for a nested name such as items[0][qty], whose error Laravel stores as items.0.qty, and for a list such as tags[]. In a Livewire form, the error disappears once the field passes validation.
Indeterminate State
The indeterminate state is useful for "parent" checkboxes when only some of their children are checked — e.g. a "Select all" control. The demo below uses Alpine.js to keep the parent in sync with its children:
The indeterminate state is a DOM property, input., with no HTML attribute behind
it, so the server cannot render it. WireKit writes data-wk-indeterminate="true" or "false" on the
input and applies the property whenever that attribute changes. A third state that arrives with a
Livewire update shows as well, and a return to false clears it. x-bind:indeterminate, as in the
demo above, covers a state that lives in Alpine.
It is not x-effect either: an effect over a value the server rendered runs once, as x-init
does, so a third state that arrives with a later update would never show. To confirm the
capability in an installed copy, look for data-wk-indeterminate in the checkbox view rather
than for x-effect.
Important: When binding an array-style
name(e.g.name="stack[]") with Alpine'sx-model, drop thevalue="..."attribute and bind to a boolean state (one key per checkbox), not to an array. Withvaluepresent, Alpine expectsx-modelto target an array and will silently mis-render the checked state. WireKit auto-generates unique DOM ids for array-style names so<label for>keeps working, but thex-model/valuesemantics remain your responsibility.
With Rich Label (Slot)
For labels that contain links or formatting — common in GDPR/privacy consent checkboxes — use the default slot instead of the label prop:
The slot content is rendered as raw HTML, so links, <strong>, <em>, and other inline elements work. A link in the sentence opens its page; the next section opens it in a modal instead, so the reader keeps a half-filled form. When both label and slot content are provided, the slot takes precedence. Content that keeps to the height of a line stands centered beside the box. A swatch in the label takes the height of the line and reaches equally above and below it, so a swatch and a name in one inline row stand centered too: <span class="inline-flex items-center gap-[var(--gap-wk-xs)]">.
Open Links in a Modal
A common pattern for newsletter sign-ups: link the privacy policy and terms to static pages that open in a WireKit modal instead of navigating away.
A modal.trigger with for opens the modal of that name from inside the checkbox's sentence: it brings its own Alpine scope, so it works in a <label> and under a strict Content Security Policy, and a click on it does not tick the checkbox. With href it stays a link, so a reader without JavaScript still reaches the document they agree to. See Opening a modal from somewhere the modal cannot reach.
Livewire Integration
Bind a checkbox to a boolean Livewire property via wire:model.live for single-toggle controls. For multi-select groups, share a name="…[]" across the group with a unique value per checkbox and bind every input to the same array property — the framework collects checked values into the array.
<x-wirekit::checkbox name="terms" label="Accept terms" wire:model.live="acceptedTerms" />
{{-- Array binding (multi-select) --}}
<x-wirekit::checkbox name="tags[]" value="php" label="PHP" wire:model.live="selectedTags" />
<x-wirekit::checkbox name="tags[]" value="js" label="JavaScript" wire:model.live="selectedTags" />
A single checkbox needs a bool property, or a model attribute with a boolean cast. A number, such as a tinyint column without the cast, is taken for the box's value rather than its state, so the box shows unchecked whatever the property holds and does not follow a value the server sets. In debug mode the component logs a warning for a binding to a number.
A checkbox that calls an action of its own, wire:click="archive" with :checked="$archived", shows the state the server rendered once the request has ended, as a toggle does: an action the server refuses leaves the box as it was.
Picking a Range With Shift
Put x-wk-range-select on the element that holds a list of checkboxes, a table body for one, and a click with Shift held gives every checkbox from the one clicked last to this one the state this click gives it, as a mail client or a file manager does. A Shift click that clears a ticked box clears the range. Each checkbox in the range is clicked in turn, so wire:model on an array, x-model and your own listeners hear it as they hear a click, and the text between the two clicks is not selected. A disabled checkbox keeps its state, and a checkbox the reader cannot see, in a row a filter hides or inside a closed <details>, is not part of the range, so an action on the selection afterwards reaches only rows the reader saw. A switch is a setting rather than a choice, so a toggle in a row is not part of the range, and neither is a checkbox inside an element with data-wk-range-skip, for any other box a row carries. Lists inside each other each pick in themselves: a checkbox belongs to the nearest x-wk-range-select around it, so a table body that carries one inside a bulk selection, which carries its own, picks its range once. Data tables with selectable do this by themselves.
In a table of your own, bound to one array:
{{-- 1. The directive on the body: the rows are the range --}}
<x-wirekit::table>
<x-wirekit::table.body x-wk-range-select>
@foreach ($orders as $order)
{{-- 2. A key per row, so a Livewire update keeps the boxes the range is counted on --}}
<x-wirekit::table.row wire:key="order-{{ $order->id }}">
<x-wirekit::table.td>
{{-- 3. Every box bound to the same array --}}
<x-wirekit::checkbox wire:model.live="selected" value="{{ $order->id }}" :label="$order->number" />
</x-wirekit::table.td>
</x-wirekit::table.row>
@endforeach
</x-wirekit::table.body>
</x-wirekit::table>
The directive is in wirekit.js, wirekit-alpine. and the ESM build.
Optimistic UI
Pass the name of the Livewire method this component should call and the change appears immediately, then confirms or undoes itself when the server answers:
<x-wirekit::checkbox
name="notify"
label="Notify me"
:checked="$notify"
optimistic="toggleNotify"
/>
Load wirekit-optimistic. alongside whichever bundle you already use — it is a separate file so applications that do not use it pay nothing for it:
@wirekitScripts
<script src="{{ asset('vendor/wirekit/wirekit-optimistic.js') }}" defer></script>
Try it
The demo below runs the real path: the change shows immediately, the outline says it is provisional, and the server's answer either confirms it silently or takes it back.
The <livewire:demos.…> wrapper above exists only on this site — it supplies the demo
methods so the page can show a real round trip. The block under it is what you write.
The browser has already ticked the box by the time any handler runs, so what this adds is the confirmation, the undo, and the announcement. Pass the current value with :checked so the component knows where it started; optimistic replaces wire:model.live rather than joining it.
What a screen reader hears is the same for every component that supports this, and it is written out in full — one hedged announcement at the change, silence on confirmation, one more only if the server refuses, and focus that never moves — in Optimistic UI — the announcement contract. That page is also where the boundary is stated: this covers mutations, not sorting, filtering or pagination.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
optimistic |
string|null |
null |
Livewire method to call, showing the new state before the server confirms it. See Optimistic UI. |
optimisticArgs |
array |
[] |
Extra arguments appended to the optimistic action call, after the new value — the row this control belongs to. |
label |
string|null | null |
Text next to the checkbox |
hideLabel |
bool | false |
Render the label sr-only (kept as the control's accessible name) — for a checkbox in a table column whose header already names it. Same prop as input / select / textarea / combobox |
hint |
string|null | null |
Helper text below. With variant="card" it is the description under the name, inside the card. See Card Variant |
help |
string|null | null |
An explanation of the field, shown in a tooltip from a question mark beside the label and read as the field's description. Needs a label to stand beside. See Help beside the label |
error |
string|false|null | null |
Error message (also triggers aria-invalid). false shows none and leaves the $errors bag alone, see Turning an Error Off |
groupError |
bool | true |
Take the surrounding field.set's group error, or decline it with :group-error="false". A control that belongs to the group but neither causes the rejection nor can resolve it is then neither marked aria-invalid by the group nor described by its message; its own error, its own hint and the set's hint are unaffected |
indeterminate |
bool | false |
Show dash instead of check (requires Alpine) |
size |
string | 'md' |
Box size — sm, md, or lg |
variant |
string | 'default' |
default (inline) or card (the whole bordered card is the selectable target) |
announceError |
bool|null | null |
Render the error message in an aria-live="polite" region so a validation error that appears after render reaches a screen reader. Precedence: this prop, then the parent <x-wirekit::form :announce-errors>, then config('wirekit.a11y.announce_error'). Set false when the page runs its own live region. |
loadingTarget |
string|null | null |
The Livewire action whose request holds the control's busy state, as on a button: while that action is in flight the control is disabled, and any other request leaves it alone. |
disableOnLoading |
bool | true |
false marks the control aria-busy during that request instead of disabling it, so it keeps the focus, which a disabled control loses the moment it is disabled |
scope |
string|null | null |
Scoped personalization name |
Slots
| Slot | Description |
|---|---|
| Default | Rich HTML label content (links, formatting). Takes precedence over the label prop. |
labelAfter |
Markup after the label and its help question mark, in the same row and outside both, such as a badge that says a setting is not decided yet. See A Mark After the Label. |
trailing |
With variant="card", the end of the card's row: a price, a logo or an image. It is not part of the checkbox's name, and it takes no button or link, since the whole card toggles the checkbox. Outside a card it is reported and not rendered. See Card Variant. |
All other attributes pass through to <input>, including name, id, checked, disabled, value, wire:model.
Accessibility
- Uses a native
<input type="checkbox">— all keyboard and screen-reader behavior is inherited from the browser. - The visual box and checkmark are purely decorative (
aria-hidden="true"). - Focus ring appears on the box when the hidden input receives keyboard focus.
aria-invalidandaria-describedbyare set automatically whenerrororhintare present.- A card is the checkbox's
<label>, so everything in it would be read into the checkbox's name. With ahintor atrailingslot, the checkbox takes its name from the label text alone througharia-labelledby, and the hint describes it. Anaria-labeloraria-labelledbyof your own on the checkbox takes precedence. - Inside
<x-wirekit::, the checkbox also points at the group's hint, or at the group's error while it carriesfield. set> aria-invalid. A message for the group renders once, above the checkboxes. - A group that needs at least one box checked takes
requiredon itsfield.set: the legend shows the asterisk and says "(required)" to a screen reader, which no attribute on a checkbox could say for the group. A checkbox withrequiredof its own means that this one box must be checked. - A required box the browser stops a form at says why under its label, in the browser's own words and the reader's language. The box is described by that message and carries
aria-invalid="true"while it stands, and the message goes once the box is checked or its form is reset. A box that shows anerrorof your server keeps that one alone, as on input. - A label in another language than the page, such as a language's own name, takes
lang. It goes on the label, which holds the words and the checkbox, so a screen reader says them in that language's voice:
<x-wirekit::checkbox name="languages[]" value="ja" label="日本語" lang="ja" />
Keyboard Interaction
| Key | Action |
|---|---|
Tab |
Move focus to the checkbox |
Space |
Toggle the checked state |
Shift + Space |
In a list with x-wk-range-select, give every checkbox from the one clicked last to this one the state this one takes |
Pitfalls
- Don't leave a checkbox without a label. The
labelprop or the default slot names the checkbox and makes the whole label clickable. Where the label must not show,hide-labelkeeps it for a screen reader. - Don't wrap a checkbox in a
<button>. The component already renders an interactive<input type="checkbox">— wrapping it in another interactive element confuses focus order.
Design Tokens
| Token | Purpose |
|---|---|
--color-wk-accent |
Fill color when checked |
--color-wk-accent-fg |
Checkmark + dash color |
--color-wk-accent-text |
Border of a chosen card (variant="card") |
--color-wk-bg-input |
Unchecked box background |
--color-wk-border-strong / --color-wk-border-error |
Box border |
--radius-wk-sm |
Box corner radius |
--color-wk-ring |
Focus ring |
Personalization blocks
Five visual zones are resolvable through WireKit:: / WireKit::, and a config override under components. reaches the same keys:
| Block key | Applies to |
|---|---|
checkbox.base |
The visible box — fill, border, focus ring, hit area, and the step that lowers it beside a taller line |
checkbox.label |
The wrapping <label> — its display mode, gap and padding (both variants) |
checkbox.text |
The visible label text, whether it comes from the label prop or the slot, and the step that lowers it beside a taller box |
checkbox.description |
The hint inside a card, under the name |
checkbox.trailing |
What the trailing slot holds at the end of a card's row, and where it stands there |
Making the checkbox a full-width row
The default label is inline-flex, so it is exactly as wide as its content. That is right for a consent line and wrong for an option list, where a code or a count belongs at the end of the row: with an inline-flex wrapper there is no edge to push it to, and flex-1 inside the slot has nothing to stretch against.
Passing class="flex w-full" on the tag does not change this — the attribute bag is spread onto the <input>, not onto the <label>. Swap the display mode through the label block instead, and register it as a scope so only the call sites that want a row get one:
// app/Providers/AppServiceProvider.php
use Pushery\WireKit\WireKit;
public function boot(): void
{
WireKit::scope('option-row', [
'checkbox' => [
'classes' => [
// A closure receives the shipped classes, so this stays a delta rather
// than a copy you now own — the rest of the block keeps updating with you.
'label' => fn (string $vendor): string => str_replace('inline-flex', 'flex w-full', $vendor),
// `flex` here too, not only `flex-1`: the span stretches to the row's width
// as a flex item, but its own children stay inline until it is a flex
// container, and `ms-auto` on the trailing element has nothing to act on.
'text' => 'flex min-w-0 flex-1 items-center gap-[var(--gap-wk-sm)] text-[length:var(--text-wk-md)] text-[color:var(--color-wk-text)] select-none',
],
],
]);
}
<x-wirekit::checkbox name="attributes[]" value="{{ $attribute->id }}" scope="option-row">
<span class="truncate">{{ $attribute->name }}</span>
<span class="ms-auto shrink-0 text-[length:var(--text-wk-xs)] text-[color:var(--color-wk-text-muted)]">{{ $attribute->code }}</span>
</x-wirekit::checkbox>
The text block is also what decouples the label's text size from the size prop, which sizes the box only.
A plain-string override replaces the block's whole class string, so prefer the closure form above when you only want to change one thing. And a utility that appears only inside a personalize() / scope() call is outside Tailwind's content scan — it needs an @source line pointing at that file, or the class resolves to no CSS and the change silently does nothing. See Class overrides.
hideLabel is unaffected either way: sr-only is appended outside the block, so a replaced text block cannot accidentally unhide a label a call site asked to hide.
Further Reading
- MDN:
<input type="checkbox"> - WAI-ARIA Checkbox Pattern
- MDN:
aria-checked— when building custom checkboxes - MDN:
:checkedpseudo-class