Checkbox
A checkbox allows users to select or deselect a predefined option independently. It can also be applied to create an on/off switch.
Related checkboxes are often placed in an input group (See the Input Group page for more information). A checkbox that controls a group of other checkboxes shows a mixed state when some but not all of them are checked.
Accessibility Features
Feature types:
Required
Recommended
- An input field must have its own visible
<label>, associated via matchingforandidattributes or nesting. Multiple interactive controls must not be nested inside a single<label>. type="checkbox"provides the checkbox role and behavior as well as communicates the checked state.indeterminateon a checkbox communicates the mixed state to screen readers.aria-controlson the parent checkbox points to the checkboxes it controls.
Checkbox
Example
Code Snippet
Switch
A switch is a binary toggle that turns a setting on or off and shares the same underlying <input> element as a checkbox. The native checkbox is usually visually hidden, and the visual appearance of the switch is implemented manually.
- The native checkbox must remain in the accessibility tree and keep a visible keyboard focus indicator, even when it is visually hidden.
role="switch"identifies the control as an on/off switch and overrides the implicit checkbox role.