Checkbox
Capture an independent checked, unchecked, or mixed choice.
I agree to the privacy policy and terms of service.
Anatomy#
Usage#
Use Checkbox for an independent boolean or mapped choice that can be selected alongside other choices. Use Switch when the control represents an immediate on/off setting. Use CheckboxGroup when several choices submit as one array.
State and forms#
Use checked with onCheckedChange for controlled state, or defaultChecked for an initial value.
Pass checked="indeterminate" from aggregate selection state; it shows the mixed presentation
without adding a third submitted value. onCheckedChange fires only for user toggles, never while
disabled or readOnly, and toggling from 'indeterminate' checks the box.
trueValue and falseValue map the checked state to domain values; onCheckedChange receives them
and a bound form.Field stores them. Native form submission uses value while checked, or falls
back to a string or number trueValue (or 'on' otherwise). An unchecked or indeterminate checkbox
contributes no entry.
Layout#
label and description render beside the control and link to it for assistive technology. Set
variant="card" to draw a bordered card whose whole surface toggles the checkbox, except for
interactive content inside it.
indicatorPosition places the control at the leading (default) or trailing edge, or hides it
visually with hidden. size accepts sm, md (default), or lg.
Read-only and disabled#
disabled removes the control from normal interaction and native form submission. readOnly
preserves the value and focusability while preventing changes.
Examples#
Indeterminate and custom icons#
Pass checked="indeterminate" for partial selection states, and override the default marks with
checkedIcon and indeterminateIcon.
Custom values#
Map checked and unchecked to application strings with trueValue and falseValue. Callbacks and
schema fields then receive those strings instead of booleans.
Custom values in form#
Combine trueValue and falseValue with form.Field so schema validation and form submission use
custom string values directly without boolean mapping.
Form#
Bind Checkbox to form.Field to validate required acceptance through the form schema.
Controlled#
Control checked with onCheckedChange to sync state with surrounding UI.
Disabled and read-only#
disabled removes the control from interaction and native submit. readOnly stays focusable and
submits, but rejects changes.
API Reference#
Attributes#
data-checkeddata-disableddata-indeterminatedata-invaliddata-readonlydata-requireddata-uncheckedProps#
Props for the Checkbox component. Renders a <div> element by default.