Skip to content

Checkbox

Selects any number of options, with checked, unchecked and indeterminate states.

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

Keyboard

Checkbox keyboard
KeyAction
TabMoves focus to the checkbox, and on to the next element.
SpaceChecks or unchecks it.

Enter doesn't toggle a checkbox, as with a native one; in a form it submits the form.

Screen reader

Role
checkbox: a visually hidden native <input type="checkbox"> (React Aria useCheckbox), inside a <label>.
Accessible name
Its label (children), or aria-label or aria-labelledby without one. One of the three is required.
States announced
Checked, not checked, or mixed ("partially checked") with indeterminate; disabled; required (aria-required, or the native required with validationBehavior="native"); invalid (aria-invalid).
  • The drawn box, check mark and dash are hidden from assistive tech; the native input carries the state, so forms and labels work as they do natively.
  • indeterminate only changes what is shown and announced; the checked state underneath stays as it was until the user acts.

Focus

  • A disabled checkbox can't be focused. A read-only one can, but can't be changed.
  • Keyboard focus shows M3's focus indicator around the 40px control: a 3px secondary outline 2px outside it, with the focus state layer. Pointer presses show no ring.

Touch target

  • The 18px box sits in a 40px control with an invisible 48 × 48px touch target. The whole label is part of the target too, since the root is a <label>.
  • With density (or the theme's), the control loses 4px a step, to 28px at -3, and the 48 × 48px target stays, reaching past the control. M3 asks not to apply density by default: offer it as the reader's choice. Checkboxes you stack yourself need their rows 48px apart, top to top, so two targets never overlap: 8px between them at density 0 and 4px more a step (20px at -3; gap-[calc(8px-var(--md-sys-density,0)*4px)]), as RadioGroup spaces its options, or use a List of checkbox items.

Motion

Under reduced motion the check mark appears at once instead of drawing in, and the box fills with a fade only. The press ripple appears at full size without growing.

What you need to do

  • Give every checkbox a visible label that says what checking it means.
  • For a parent checkbox, set indeterminate while some, but not all, of its children are checked, and update it and the children in onCheckedChange.
  • Put related checkboxes under a visible heading or in a fieldset with a legend, so the group has a name.
  • Show an error message next to an invalid checkbox and link it with aria-describedby; the checkbox only shows the error colour.