Radio Group Example Using Roving tabindex
Important Note About Use of This Example
Note: This is an illustrative example of one way of using ARIA that conforms with the ARIA specification.
- There may be support gaps in some browser and assistive technology combinations, especially for mobile/touch devices. Testing code based on this example with assistive technologies is essential before considering use in production systems.
- The ARIA-AT project plans to provide measurements of this example's assistive technology support by the end of 2020.
- Robust accessibility can be further optimized by choosing implementation patterns that maximize use of semantic HTML and heeding the warning that No ARIA is better than Bad ARIA.
This example implements the features of the Radio Group Design Pattern for two radio groups -- one for choosing a pizza crust and another for choosing a delivery method. This implementation uses a roving tabindex for managing focus within the radio group.
Similar examples include:
- Radio Group Example Using aria-activedescendant: Radio button group that uses aria-activedescendantfor managing keyboard focus.
Example
Pizza Crust
              Regular crust
            
            
              Deep dish
            
            
              Thin crust
            
          Pizza Delivery
              Pickup
            
            
              Home Delivery
            
            
              Dine in
            
          Accessibility Features
- Uses CSS attribute selectors for synchronizing aria-checkedstate with the visual state indicator.
- 
            Uses CSS :hoverand:focuspseudo-classes for styling visual keyboard focus and hover.- Focus indicator encompasses both radio button and label, making it easier to perceive which option is being chosen.
- Hover changes background of both radio button and label, making it easier to perceive that clicking either the label or button will activate the radio button.
- Because transparent borders are visible on some systems with high contrast enabled, only the focused element has a visible border. When focusable elements are not focused, they have a 0-width border and additional padding equal in width to the border that is used to indicate focus.
 
Keyboard Support
| Key | Function | 
|---|---|
| Tab | 
 | 
| Space | 
 | 
| Down arrow Right arrow | 
 | 
| Up arrow Left arrow | 
 | 
Role, Property, State, and Tabindex Attributes
| Role | Attributes | Element | Usage | 
|---|---|---|---|
| radiogroup | div | 
 | |
| aria-labelledby="[IDREF]" | div | Refers to the element that contains the label of the radio group. | |
| radio | div | 
 | |
| tabindex="-1" | div | 
 | |
| tabindex="0" | div | 
 | |
| aria-checked="false" | div | 
 | |
| aria-checked="true" | div | 
 | 
Javascript and CSS Source Code
HTML Source Code
<div role="radiogroup"
     aria-labelledby="group_label_1"
     id="rg1">
  <h3 id="group_label_1">
    Pizza Crust
  </h3>
  <div role="radio"
       aria-checked="false"
       tabindex="0">
    Regular crust
  </div>
  <div role="radio"
       aria-checked="false"
       tabindex="-1">
    Deep dish
  </div>
  <div role="radio"
       aria-checked="false"
       tabindex="-1">
    Thin crust
  </div>
</div>
<div role="radiogroup"
     aria-labelledby="group_label_2"
     id="rg2">
  <h3 id="group_label_2">
    Pizza Delivery
  </h3>
  <div role="radio"
       aria-checked="false"
       tabindex="0">
    Pickup
  </div>
  <div role="radio"
       aria-checked="false"
       tabindex="-1">
    Home Delivery
  </div>
  <div role="radio"
       aria-checked="false"
       tabindex="-1">
    Dine in
  </div>
</div>