Checkbox
Turn an option on or off as part of a form people will review and save.
When to use it
Use Checkbox for options that apply when the form is submitted, or for picking several items from a list. It can also show a mixed state when some of a group is selected.
If the change should happen the moment itโs flipped, use Switch.
CheckboxThis page
Saved with the form.
Options reviewed before submitting.
How it behaves
Use defaultChecked for local state or checked/onCheckedChange for controlled state. Base UI forwards name, value, required, readOnly, and inputRef to its form behavior.
Associate a visible label using htmlFor and id. Space toggles the focused checkbox; disabled controls cannot be changed.
Pass indeterminate for a mixed selection; it is separate from checked. JZB shows a dash for mixed and a checkmark for checked.
Use aria-invalid and connect an error with aria-describedby. Validation and clearing an indeterminate state belong to the consumer.
The checkmark draws along its stroke in 220ms using CSS, reversing when cleared. The mixed-state dash crossfades. Reduced motion uses a 100ms fade without drawing; focused keyboard changes are immediate.
Build it
Add it with the shadcn CLI:
1pnpm dlx shadcn@latest add https://jzbui.com/r/checkbox.jsonA complete example. Change the values to fit your product:
1234567891011import { Checkbox } from "@/components/ui/checkbox"
<div className="flex items-start gap-3"> <Checkbox id="checklist" name="checklist" defaultChecked aria-describedby="checklist-hint" /> <div> <label htmlFor="checklist" className="label-md">Include a starter checklist</label> <p id="checklist-hint" className="body-sm text-muted-foreground"> Add a few tasks to help the team get started. </p> </div></div>The full source is yours to edit once installed: