Jone

Checkbox

A high-quality, unstyled React checkbox component that is easy to customize.

An easily stylable checkbox component.

Usage guidelines

  • Form controls must have an accessible name: It can be created using a <label> element or the Field component. See Labeling a checkbox and the forms guide.

Anatomy

Import the component and assemble its parts:

Anatomy
import { Checkbox } from '@base-ui/react/checkbox';

<Checkbox.Root>
  <Checkbox.Indicator />
</Checkbox.Root>;

Examples

Labeling a checkbox

An enclosing <label> is the simplest labeling pattern:

Wrapping a label around a checkbox
<label>
  <Checkbox.Root />
  Accept terms and conditions
</label>

Rendering as a native button

By default, <Checkbox.Root> renders a <span> element to support enclosing labels. Prefer rendering the checkbox as a native button when using sibling labels (htmlFor/id).

Sibling label pattern with a native button
<div>
  <label htmlFor="notifications-checkbox">Enable notifications</label>
  <Checkbox.Root id="notifications-checkbox" nativeButton render={<button />}>
    <Checkbox.Indicator />
  </Checkbox.Root>
</div>

Native buttons with wrapping labels are supported by using the render callback to avoid invalid HTML, so the hidden input is placed outside the label:

Render callback
<Checkbox.Root
  nativeButton
  render={(buttonProps) => (
    <label>
      <button {...buttonProps} />
      Enable notifications
    </label>
  )}
/>

Form integration

Use Field to handle label associations and form integration:

Using Checkbox in a form
<Form>
  <Field.Root name="stayLoggedIn">
    <Field.Label>
      <Checkbox.Root />
      Stay logged in for 7 days
    </Field.Label>
  </Field.Root>
</Form>

API reference

Root

NameTypeDefaultDescription
idOptionalstring | undefinedThe id of the input element.
nameOptionalstring | undefinedundefinedIdentifies the field when a form is submitted.
checkedOptionalboolean | undefinedundefinedWhether the checkbox is currently ticked. To render an uncontrolled checkbox, use the `defaultChecked` prop instead.
defaultCheckedOptionalboolean | undefinedfalseWhether the checkbox is initially ticked. To render a controlled checkbox, use the `checked` prop instead.
disabledOptionalboolean | undefinedfalseWhether the component should ignore user interaction.
readOnlyOptionalboolean | undefinedfalseWhether the user should be unable to tick or untick the checkbox.
requiredOptionalboolean | undefinedfalseWhether the user must tick the checkbox before submitting a form.
indeterminateOptionalboolean | undefinedfalseWhether the checkbox is in a mixed state: neither ticked, nor unticked.
inputRefOptionalReact.Ref<HTMLInputElement> | undefinedA ref to access the hidden `<input>` element.
parentOptionalboolean | undefinedfalseWhether the checkbox controls a group of child checkboxes. Must be used in a [Checkbox Group](https://base-ui.com/react/components/checkbox-group).
uncheckedValueOptionalstring | undefinedThe value submitted with the form when the checkbox is unchecked. By default, unchecked checkboxes do not submit any value, matching native checkbox behavior.
valueOptionalstring | undefinedThe value of the selected checkbox.

Indicator

NameTypeDefaultDescription
keepMountedOptionalboolean | undefinedfalseWhether to keep the element in the DOM when the checkbox is not checked.

On this page