Tri-State Checkbox With Grouping Label Examples

Following are three example implementations of the design pattern for checkbox that demonstrate how to make a widget that uses the mixed value for aria-checked. These examples also show three different ways of labeling a collection of checkboxes so screen reader users can perceive that all members of the collection are part of a logical group.

In the below examples, a set of checkboxes is used to choose condiments for a sandwich. The user can use the first checkbox, labeled "All Condiments", to quickly specify a desire for either all or none of the condiments. If the user chooses to have some but not all condiments, the "All Condiments" checkbox will reflect that state as "partially checked"; this is the mixed value of aria-checked.

Examples

Note that the conditions and actions that cause screen readers to announce the grouping labels in the following 3 examples vary from one screen reader to another; such assistive technology behaviors are not standardized.

Example 1: group label using fieldset and legend

This is the preferred implementation whenever feasible.

Sandwich Condiments

In this implementation:

Example 2: Group Label Using role = group

Sandwich Condiments

In this implementation:

Example 3: Group Label Appended to Individual Checkbox Labels

Sandwich Condiments
Lettuce
Tomato
Mustard
Sprouts

In this implementation:

Common Accessibility Features

Keyboard Support

Key Function
Tab Moves keyboard focus to checkbox.
Space Toggle the checkbox option either true, false or mixed. False is the default.

ARIA Roles, Properties and States

Role Property/State Usage
checkbox Identify div as Checkbox widget
aria-checked Indicate state of checkbox:
  • Checked (e.g. aria-checked=true)
  • Unchecked (e.g. aria-checked=false)
  • Mixed (e.g. aria-checked=mixed)
aria-labelledby Used to include grouping label in the label of each checkbox

Javascript and CSS Source Code

HTML Source Code

Example 1: group label using fieldset and legend

Example 2: Group Label Using role = group

Example 3: Group Label Appended to Individual Checkbox Labels