Checkbox
Turns one option on or off, or picks several from a list. Outlined, with a dark check when selected.
Usage
pnpm dlx shadcn@latest add checkboxThen replace components/ui/checkbox.tsx with the Matrix version. It keeps shadcn's API (checked, onCheckedChange, defaultChecked) and adds the Matrix sizes and look.
import { Checkbox } from '@/components/ui/checkbox';
import { Field, FieldLabel } from '@/components/ui/field';
<Field orientation="horizontal">
<Checkbox id="terms" />
<FieldLabel htmlFor="terms">I agree to the terms</FieldLabel>
</Field>Variants
States
Focus
Disabled · on
Disabled · off
Invalid
Sizes
sm · 16px (default)
md · 20px
sm sits next to 14px text in forms, lists and tables. md is for touch and for checkboxes that are the main control on a screen.
With a label
A short email with what your agents did this week.
Clicking the label toggles the checkbox, so the whole row is a target.
Behavior
Space toggles; Enter doesn't
Space checks and unchecks, the same as a native checkbox. Enter is left for submitting the form around it.
Indeterminate is set from code
Use checked="indeterminate" for a "select all" box when only some items in the group are selected. Clicking it selects all.
API reference
Prop
Type
Guidelines
- Use a checkbox for choices saved with a form, consent ("I agree to the terms") and multi-select lists.
- Write labels as a positive statement of what checking does: "Send a weekly summary", not "Don't send emails".
- Link the label with
htmlForso clicking the text toggles the box. - Don't use a checkbox for a setting that takes effect immediately; use a Switch.
- Don't use checkboxes when only one option can be picked; use a Radio group.