Checkbox

Checkbox gives users a binary choice between multiple options in a series.

Give FeedbackWAI-ARIABundle Size
index.tsx

Installation

Base UI components are all available as a single package.

npm install @base_ui/react

Once you have the package installed, import the component.

import { Checkbox } from '@base_ui/react/Checkbox';

Anatomy

Checkbox is composed of two components:

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

Indeterminate state

To make the Checkbox indeterminate, add the indeterminate prop to override the appearance of the Checkbox. The Checkbox remains in an indeterminate state regardless of user interaction until set back to false.

UnstyledCheckboxIndeterminate.tsx

The primary use case for an indeterminate checkbox is representing the state of a parent checkbox where only some of its children are checked.

UnstyledCheckboxIndeterminateGroup.tsx

It's a visual-only state, so its internal checked state can still be changed.

Overriding default components

Use the render prop to override the rendered checkbox or indicator element with your own components.

<Checkbox.Root render={(props) => <MyCheckbox {...props} />}>
  <Checkbox.Indicator render={(props) => <MyCheckboxIndicator {...props} />} />
</Checkbox.Root>

Accessibility

Ensure the Checkbox has an accessible name via a <label> element.

<Checkbox.Root id="my-checkbox">
  <Checkbox.Indicator />
</Checkbox.Root>
<label htmlFor="my-checkbox">
  My label
</label>

API Reference

CheckboxRoot

The foundation for building custom-styled checkboxes.

PropTypeDefaultDescription
checkedboolundefinedIf true, the component is checked.
classNameunionClass names applied to the element or a function that returns them based on the component's state.
defaultCheckedboolfalseThe default checked state. Use when the component is not controlled.
disabledboolfalseIf true, the component is disabled.
indeterminateboolfalseIf true, the checkbox will be indeterminate.
inputRefunionThe ref to the input element.
namestringundefinedName of the underlying input element.
onCheckedChangefuncCallback fired when the checked state is changed.
parentboolfalseIf true, the checkbox is a parent checkbox for a group of child checkboxes.
readOnlyboolfalseIf true, the component is read only.
renderunionA function to customize rendering of the component.
requiredboolfalseIf true, the input element is required.

CheckboxIndicator

The indicator part of the Checkbox.

PropTypeDefaultDescription
classNameunionClass names applied to the element or a function that returns them based on the component's state.
keepMountedbooltrueIf true, the indicator stays mounted when unchecked. Useful for CSS animations.
renderunionA function to customize rendering of the component.

Contents