ARIA checkbox: Mixed State Checkbox with Grouping Label

Authoring Practice Design Patten for Checkbox

Checkbox Examples

1. Checkbox example with fieldset and legend

Sandwich Condiments

2. Checkbox example with role = group

Sandwich Condiments

3. Checkbox example with aria-labelledby

Sandwich Condiments
Lettuce
Tomato
Mustard
Sprouts

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

Source Code

HTML Code

1. Checkbox example with fieldset and legend


<div>
  <fieldset>
    <legend>
      Sandwich Condiments
    </legend>
    <div role="checkbox"
         class="group_checkbox"
         aria-checked="false"
         tabindex="0"
         onclick="toggleGroupCheckbox(event)"
         onkeydown="toggleGroupCheckbox(event)"
         onfocus="focusCheckbox(event)"
         onblur="blurCheckbox(event)">
      <img src="./images/checkbox-unchecked-black.png" alt="">
       All condiments
    </div>
    <label>
      <input type="checkbox">
      Lettuce
    </label>
    <label>
      <input type="checkbox">
      Tomato
    </label>
    <label>
      <input type="checkbox">
      Mustard
    </label>
    <label>
      <input type="checkbox">
      Sprouts
    </label>
  </fieldset>
</div>

2. Checkbox example with role = group


<div>
  <div role="group" aria-label="sandwitch condiment">
    <div>
      Sandwich Condiments
    </div>
    <div role="checkbox"
         class="group_checkbox"
         aria-checked="false"
         tabindex="0"
         onclick="toggleGroupCheckbox(event)"
         onkeydown="toggleGroupCheckbox(event)"
         onfocus="focusCheckbox(event)"
         onblur="blurCheckbox(event)">
      <img src="./images/checkbox-unchecked-black.png" alt="">
       All condiments
    </div>
    <label>
      <input type="checkbox">
      Lettuce
    </label>
    <label>
      <input type="checkbox">
      Tomato
    </label>
    <label>
      <input type="checkbox">
      Mustard
    </label>
    <label>
      <input type="checkbox">
      Sprouts
    </label>
  </div>
</div>

3. Checkbox example with aria-labelledby


<div>
  <div>
    Sandwich Condiments
  </div>
  <div role="checkbox"
       class="group_checkbox"
       aria-checked="false"
       aria-labelledby="label0 group1"
       tabindex="0"
       onclick="toggleGroupCheckbox(event)"
       onkeydown="toggleGroupCheckbox(event)"
       onfocus="focusCheckbox(event)"
       onblur="blurCheckbox(event)">
    <img src="./images/checkbox-unchecked-black.png" alt="">
    <span>
       All condiments
    </span>
  </div>
  <div class="checkbox">
    <input type="checkbox" aria-labelledby="label1 group1">
    <span>
      Lettuce
    </span>
  </div>
  <div class="checkbox">
    <input type="checkbox" aria-labelledby="label2 group1">
    <span>
       Tomato
    </span>
  </div>
  <div class="checkbox">
    <input type="checkbox" aria-labelledby="label3 group1">
    <span>
      Mustard
    </span>
  </div>
  <div class="checkbox">
    <input type="checkbox" aria-labelledby="label4 group1">
    <span>
       Sprouts
    </span>
  </div>
</div>