Primitives
Checkbox primitive
Lower-level checkbox anatomy for custom label layouts.
Use the Checkbox primitive when your layout owns the label, such as a table row, or when the label
needs custom content. For a normal labelled checkbox, use
CheckboxField.
Anatomy
CheckboxRoot is the semantic root. It owns the selection, state, validation, form, and size props.
id, className, and ref target the root element. inputId and inputRef target the input.
CheckboxLabel is the clickable native <label>. It holds the hidden input, CheckboxControl, and
usually the label text. Like React Aria's CheckboxButton, it takes className, style, and
children as functions of the checkbox state, as well as render, slot, and event handlers.
CheckboxControl sizes the visual affordance to the label's first line, and CheckboxIndicator
draws the box and its selected and indeterminate states. Put the control before the label text.
Description and error
Wrap CheckboxLabel in InlineField to add a description and an
errorMessage. The errorMessage shows while the root is invalid. For a custom arrangement, place
FieldDescription and FieldError inside the root instead of InlineField.
Labels
CheckboxLabel is a native <label>, so it takes textual, non-interactive content only. Place
links and buttons outside it.
When another part of the layout draws the visible label, leave the text out of CheckboxLabel.
Place a FieldLabel and a FieldDescription anywhere inside
CheckboxRoot. The root connects them to the input, so the label names the checkbox, clicking it
toggles the checkbox, and the description describes it. Pass no ids. The
Switch primitive shows the same pattern.
Put the label text in either CheckboxLabel or FieldLabel, not both. The checkbox's name joins
the text from each. Pass aria-label when no visible text names the checkbox.
CheckboxLabel draws no required marker. With isRequired on CheckboxRoot, a FieldLabel does,
as Required fields describes. Show the required state in your own
content when you use CheckboxLabel for the text.
Text in the label
Set slot={null} on each Text you place in CheckboxLabel, so it renders as label content rather
than a description or error.
API
CheckboxRootProps
CheckboxRootProps also accepts compatible DOM and ARIA attributes and event handlers for its rendered element.
CheckboxLabelProps
CheckboxLabelProps also accepts compatible DOM and ARIA attributes and event handlers for its rendered element.
CheckboxControlProps
CheckboxControlProps also accepts compatible DOM and ARIA attributes and event handlers for its rendered element.
CheckboxIndicatorProps
CheckboxIndicatorProps also accepts compatible DOM and ARIA attributes and event handlers for its rendered element.