Checkbox
A control that lets users check or uncheck an option.
A checkbox lets users check or uncheck one option without changing any other. Its label names the option, and a click on the label changes the checkbox just as a click on the box does.
Usage
Examples
Checked by Default
Some options hold true for most users, such as keeping a filter for the next visit. With defaultChecked, the checkbox starts checked, so users only act when the option does not suit their case.
Controlled
Often the application needs the state of an option, for example to offer the next step only after users have confirmed it. Through checked and onCheckedChange, it holds that state itself, so the checkbox can also show a value that comes from saved data or from another part of the interface.
Indeterminate
A checkbox that stands for a whole selection is only partly true when users have chosen some of its options but not all of them. The indeterminate prop puts it in this mixed state and exposes it to assistive technology, and the checkbox stays mixed, even when users click it, until the application sets the prop to false.
Disabled
Not every option applies in every context, for example a report section without data for the chosen period. Where that is the case, disabled keeps the option in view while users can no longer check or uncheck it, and the checkbox exposes this state to assistive technology.
Read-Only
Users sometimes need to see a decision that was made elsewhere, such as a setting that headquarters defines for every branch. Once readOnly is set, users can no longer change the checkbox, yet unlike a disabled one it stays reachable with the keyboard and is submitted with the form.
Invalid
A form can require a confirmation before it accepts an entry, and users need to see at once which option is still missing. When validation fails, aria-invalid marks the checkbox as invalid, on screen as well as for assistive technology.
API Reference
| Prop | checked |
|---|---|
| Type | boolean |
| Default | – |
| Description | Sets whether the checkbox is checked and makes it controlled. Update it in onCheckedChange. |
| Prop | defaultChecked |
|---|---|
| Type | boolean |
| Default | false |
| Description | Checks the checkbox at first render. The checkbox then tracks its state itself. |
| Prop | onCheckedChange |
|---|---|
| Type | (checked: boolean, eventDetails: CheckboxRootChangeEventDetails) => void |
| Default | – |
| Description | Runs when users check or uncheck the checkbox. It receives the state that follows. |
| Prop | indeterminate |
|---|---|
| Type | boolean |
| Default | false |
| Description | Puts the checkbox in a mixed state that is neither checked nor unchecked, and exposes that state to assistive technology. The checkbox stays mixed until the prop is false, even when users click it. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from checking or unchecking the checkbox and exposes the disabled state to assistive technology. |
| Prop | readOnly |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from checking or unchecking the checkbox. Unlike a disabled checkbox, it stays focusable and is submitted with the form. |
| Prop | required |
|---|---|
| Type | boolean |
| Default | false |
| Description | Requires users to check the checkbox before they can submit the form. |
| Prop | name |
|---|---|
| Type | string |
| Default | – |
| Description | Identifies the checkbox when the form is submitted. |
| Prop | value |
|---|---|
| Type | string |
| Default | – |
| Description | Sets the value that a checked checkbox submits with the form. Without it, a checked checkbox submits "on". Inside a CheckboxGroup, it also identifies the checkbox. |
| Prop | uncheckedValue |
|---|---|
| Type | string |
| Default | – |
| Description | Sets the value that an unchecked checkbox submits with the form. Without it, an unchecked checkbox submits nothing. It has no effect without name. |
| Prop | form |
|---|---|
| Type | string |
| Default | – |
| Description | Sets the ID of the form that the checkbox belongs to. Set it when the checkbox is rendered outside of that form. |
| Prop | id |
|---|---|
| Type | string |
| Default | – |
| Description | Sets the ID of the hidden input, so that a label can refer to the checkbox with htmlFor. With nativeButton, the ID goes to the rendered button instead. |
| Prop | inputRef |
|---|---|
| Type | Ref<HTMLInputElement> |
| Default | – |
| Description | Receives the hidden input element that carries the value of the checkbox in a form. |
| Prop | parent |
|---|---|
| Type | boolean |
| Default | false |
| Description | Makes the checkbox control a group of child checkboxes. It only works inside a CheckboxGroup from @base-ui/react/checkbox-group. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the checkbox with another component. |
| Prop | nativeButton |
|---|---|
| Type | boolean |
| Default | false |
| Description | Declares whether the rendered element is a native button. Set it to true when render returns a button. |