Blocks Design System

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.

tsx
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.

Stations
Source · checkbox/alert-stations.tsx
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>
  )
}
Storm alerts

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
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>
  )
}
Public map

Props

Checkbox props
PropTypeDefaultDescription
checkedboolean—Whether the checkbox is currently ticked. To render an uncontrolled checkbox, use the `defaultChecked` prop instead.
childrenReactNode—The checkbox's label, rendered next to it inside a `<label>`.
defaultCheckedbooleanfalseWhether the checkbox is initially ticked. To render a controlled checkbox, use the `checked` prop instead.
disabledbooleanfalseWhether the component should ignore user interaction.
formstring—Identifies the form that owns the hidden input. Useful when the checkbox is rendered outside the form.
idstring—The id of the input element.
indeterminatebooleanfalseWhether the checkbox is in a mixed state: neither ticked, nor unticked.
inputRefRef<HTMLInputElement>—A ref to access the hidden `<input>` element.
namestring—Identifies the field when a form is submitted.
nativeButtonbooleantrueWhether 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.
parentbooleanfalseWhether the checkbox controls a group of child checkboxes. Must be used in a [Checkbox Group](https://base-ui.com/react/components/checkbox-group).
readOnlybooleanfalseWhether the user should be unable to tick or untick the checkbox.
renderReactElement<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.
requiredbooleanfalseWhether the user must tick the checkbox before submitting a form.
uncheckedValuestring—The value submitted with the form when the checkbox is unchecked. By default, unchecked checkboxes do not submit any value, matching native checkbox behavior.
valuestring—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.