Checkbox
A checkbox on Base UI with checked, unchecked and mixed (indeterminate) states. Pass the label as children and Checkbox renders a native <label> around the control.
import { Checkbox } from '@blocks/design-system'Checkbox is a client component. A Server Component can render it uncontrolled with defaultChecked; state and onCheckedChange belong in a client-authored caller.
A group with a parent
Control the children and derive the parent: checked when every child is, indeterminate when only some are. name and value make each checkbox submit with a native form; disabled checkboxes are skipped by Tab and left out of the submission.
Source · checkbox/alert-stations.tsx
'use client'
import { Button, Checkbox, Stack } from '@blocks/design-system'
import { useState } from 'react'
const stations = [
{ id: 'mount-hood', name: 'Mount Hood' },
{ id: 'alta', name: 'Alta' },
{ id: 'stevens-pass', name: 'Stevens Pass' },
]
export default function AlertStations() {
const [selected, setSelected] = useState<string[]>([])
const all = selected.length === stations.length
const some = selected.length > 0 && !all
return (
<Stack as="form" action="/components/checkbox" method="get" gap="sm" aria-label="Storm alerts">
<Checkbox
checked={all}
indeterminate={some}
onCheckedChange={(checked) => setSelected(checked ? stations.map((station) => station.id) : [])}
>
All stations
</Checkbox>
<Stack as="fieldset" gap="xs" paddingLeft="lg" margin="none" dangerouslySetStyle={{ border: 'none' }}>
<legend className="visually-hidden">Stations</legend>
{stations.map((station) => (
<Checkbox
key={station.id}
name="station"
value={station.id}
checked={selected.includes(station.id)}
onCheckedChange={(checked) =>
setSelected((current) => (checked ? [...current, station.id] : current.filter((id) => id !== station.id)))
}
>
{station.name}
</Checkbox>
))}
<Checkbox name="station" value="taos" disabled>
Taos (offline)
</Checkbox>
</Stack>
<div>
<Button type="submit" variant="primary">
Save alerts
</Button>
</div>
</Stack>
)
}Inside a Field
Without children, Checkbox takes its label from a surrounding Field, which also links a description.
Anyone with the link can see its readings.
Source · checkbox/in-field.tsx
import { Checkbox, Field, FieldDescription, FieldLabel } from '@blocks/design-system'
// Server-authored and uncontrolled: the label comes from Field.
export default function InField() {
return (
<Field name="public">
<FieldLabel>
<Checkbox defaultChecked />
Show this station on the public map
</FieldLabel>
<FieldDescription>Anyone with the link can see its readings.</FieldDescription>
</Field>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | Whether the checkbox is currently ticked. To render an uncontrolled checkbox, use the `defaultChecked` prop instead. |
children | ReactNode | — | The checkbox's label, rendered next to it inside a `<label>`. |
defaultChecked | boolean | false | Whether the checkbox is initially ticked. To render a controlled checkbox, use the `checked` prop instead. |
disabled | boolean | false | Whether the component should ignore user interaction. |
form | string | — | Identifies the form that owns the hidden input. Useful when the checkbox is rendered outside the form. |
id | string | — | The id of the input element. |
indeterminate | boolean | false | Whether the checkbox is in a mixed state: neither ticked, nor unticked. |
inputRef | Ref<HTMLInputElement> | — | A ref to access the hidden `<input>` element. |
name | string | — | Identifies the field when a form is submitted. |
nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
onCheckedChange | ((checked: boolean, eventDetails: { … }) => void) | — | Event handler called when the checkbox is ticked or unticked. |
parent | boolean | false | Whether the checkbox controls a group of child checkboxes. Must be used in a [Checkbox Group](https://base-ui.com/react/components/checkbox-group). |
readOnly | boolean | false | Whether the user should be unable to tick or untick the checkbox. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, CheckboxRootState> | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
required | boolean | false | Whether the user must tick the checkbox before submitting a form. |
uncheckedValue | string | — | The value submitted with the form when the checkbox is unchecked. By default, unchecked checkboxes do not submit any value, matching native checkbox behavior. |
value | string | — | The checkbox's value. Identifies it within a [Checkbox Group](https://base-ui.com/react/components/checkbox-group), falling back to `name` when omitted. When submitting a form, a checked box submits `value`; with no `value`, it submits the native "on". |
Also accepts styling escape hatches and a ref, and the native attributes of the element it renders.
Accessibility
- Space toggles the focused checkbox. A mixed parent announces “mixed”, or “partially checked”.
- Group related checkboxes in a
<fieldset>with a<legend>, which can be visually hidden when a visible heading already names the group. - A checkbox without children or a Field needs an
aria-label.