Checkbox
Turns one option on or off, or picks several from a list.
When to use
- Turn one option on or off inside a form that's saved with a button.
- Pick any number of options from a short list.
When not to use
- Exactly one option from a list: use Radio Group.
- A setting that applies as soon as it changes: use Switch.
Install
npx shadcn@latest add @clinia/checkboxAnatomy
- 1Box
data-slot="checkbox"border-input · data-checked:bg-primary - 2Check mark
data-slot="checkbox-indicator"size-3.5 · text-primary-foreground - 3Label
data-slot="label"text-sm · font-medium
Clinia rules
- The resting box has an
inputborder, which clears 3:1. Checked and indeterminate are aprimaryfill with aprimary-foregroundmark, never Trust. - Write the label as the positive statement that checking makes true:
Share with the care team, notDon't share. - The hit area extends past the 16px box (
after:-inset-x-3 after:-inset-y-2), so a click just outside the box still toggles it.
Do and don't
States
unchecked
checked
indeterminate
focus
invalid
disabled
disabled · checked
Focus cells apply the component's focus-visible classes statically. Toggle the site theme to review both themes.
Accessibility
Built in
- Focus-visible shows a solid Trust ring (
border-ring ring-3 ring-ring/30);aria-invalidswaps it to a destructive ring, but a checked box keeps its primary border even when invalid. - Base UI renders a
role="checkbox"element witharia-checked, includingmixedforindeterminate, plus a hidden native input so the value submits with the form.
Your responsibility
- Pair every checkbox with a
Label(htmlFor= the checkboxid), or give it anaria-labelwhen a row already names it, as in a table. - Group related checkboxes in a
FieldSetwith aFieldLegend, so the question is read with each option. - Use
indeterminateonly on a parent that controls a list, when some but not all children are checked.
How to test
- Press Tab to reach the checkbox: the Trust ring appears.
- Press Space: it toggles. Enter does not toggle it.
- Click the label: it toggles too.
- With a screen reader, it's announced as its label, then checkbox, then checked, not checked or mixed.
API
Every prop comes from Base UI Checkbox.
Related