CheckboxGroup
CheckboxGroup renders a set of Checkboxes.
Page navigation navigation
Once a user checks an option from a CheckboxGroup, the result should not be saved or applied until the user has explicitly submitted their input using a "save" or "submit" button. See the saving pattern guidelines for more information.
Alternative: you can use a ToggleSwitch to immediately toggle something on and off as long as it's not in the context of a bigger form that applies other input values when submitted.
Accessibility and usability expectations
Checkboxes are most commonly used as part of a CheckboxGroup.
Presentation
Cognition
- A
CheckboxGroupmust have a visible group label that provides context - If a selection from a
CheckboxGroupis required, this must be indicated in the group label, ideally using clear text such as "(required)" rather than an asterisk alone. Whilst an asterisk is sufficient to meet accessibility requirements, it's meaning may not be understood by all users, and may be difficult to see by users with low vision - Each
checkboxmust have a clear, descriptive, and permanently visible label so users understand its purpose Checkboxlabels should appear to the right of thecheckbox
Vision
- All text, group label, caption, option labels, error and success messages, must meet the minimum contrast ratio of 4.5:1
- The
checkboxborder must have a minimum contrast ratio of 3:1 against the background Checkboxfocus styles must have a minimum contrast ratio of 3:1 against the background- A
checkboxmust have a distinct checked state that does not rely on color alone
Mobility
- The clickable target area of a
checkboxmust be at least 24 by 24 CSS pixels to support users with limited dexterity
Adaptability
- Text must be resizable up to 200% and remain readable
- Layout must reflow at a 320px viewport or 400% zoom without requiring horizontal scrolling
- Text spacing must be adjustable without loss of content or functionality
Interaction
Keyboard
- Unless disabled, a
checkboxmust be focusable using theTabkey - Pressing
Spacemust check or uncheck the focusedcheckbox - A
checkboxmust not trap keyboard focus - A
checkboxmust not trigger a change of context when focused or activated
Engineering for AT Compatibility
Screen reader
- Each
checkboxmust have an associated<label>to provide an accessible name - Additional instructions or requirements should be programmatically associated using
aria-describedby - Captions or error messages for individual
checkboxshould be associated with the<input> - For group-level messaging, include the message directly within the
<legend>to ensure it is read correctly by screen readers - The
checkboxmust have the ARIA role ofcheckbox - The checked state must be conveyed using
aria-checkedor the native checked attribute - If disabled, the
disabledstate must be conveyed usingaria-disabled="true"or the nativedisabledattribute
Speech recognition
- The accessible name must include the visible text label so users can activate the
checkboxusing voice commands that match the label
Built-in accessibility features
- The text,
checkboxborder, and, custom focus style meet minimum contrast requirements - The
checkboxmust have a distinct checked state that does not rely solely on color - The
checkboxin aCheckboxGrouphave sufficient spacing to meet the minimum target and spacing size of 24 by 24 CSS pixels - The text is resizable and the text spacing adjustable. The component reflows when zoomed or viewed at a width equivalent to 320 CSS pixels
- By default, the component renders a
<fieldset>and<legend>to provide the grouping and group label, but can also usearia-labelledbyandrole="group" - The component renders a correctly associated pair of
<label>and<input type="checkbox">. Using the the native<input type="checkbox">ensures that thecheckboxconvey the correct role and selected state to screen readers and has the correct keyboard behavior - The group caption, error message and success message is automatically associated with the
<fieldset>usingaria-describedby. Whilst this works in most screen readers, a bug in NVDA means that the accessible description is not automatically announced in NVDA when acheckboxreceives focus - Option captions are automatically associated with the with the relevant
<input> - When a
checkboxis disabled, thedisabledattribute is applied and the disabled state conveyed to screen readers - When a
checkboxis given the indeterminate state,aria-checked="mixedis applied and the state conveyed to screen readers
Implementation requirements
- Ensure the
CheckboxGrouphas a visible group label that provides context. The simplest way to do this is to use aCheckboxGroup.Label. Alternatively, anaria-labelledbythat references an external label can be applied toCheckboxGroup CheckboxGroup.Labelhas avisuallyHiddenprop, but this should not be used- When using an icon for a leading visual, note that the icon doesn't have a text alternative. They are purely visual, and not conveyed to screen readers. Don't rely on these icons alone to convey meaning – make sure that the text label of the radio button provides sufficient meaning on its own
How to test the component
Integration tests
- The
CheckboxGrouphas a visible group label that provides a descriptive accessible name - Each
checkboxhas a clear and visible label that describes it's purpose - If the
checkboxincludes a leading visual icon, the input's purpose is clear from the text alone
Component tests
- When a
CheckboxGroupis given aCheckboxGroup.label, a<fieldset>containing a<legend>as the first child, is rendered - When a
CheckboxGrouphas anaria-labelledbyapplied, instead of aCheckboxGroup.label, a<div>with arole="group"and anaria-labelledbyis rendered instead of a<fieldset>and<legend> - The component renders a correctly associated pair of
<label>and<input type="checkbox"> - All text, including labels, captions, error and success messages, meets the minimum contrast requirements of 4.5:1
- The
checkboxborder, checked style and custom focus style meets the minimum contrast requirement of 3:1 - The
checkboxhave sufficient spacing to meet the minimum target and spacing size of 24 by 24 CSS pixels - The content remains readable, without requiring horizontal scrolling, when zoomed or viewed at a width equivalent to 320 CSS pixels
- If there is option caption, it is associated with the appropriate
<input>usingaria-describedby - If a
checkboxis disabled, thedisabledattribute is present - If a
checkboxis indeterminate,aria-checked="mixed"is present and conveyed to screen readers