Radio Button Example
This example implements the features of the Radio Button Design Pattern for selecting a pizza crust and delivery method.
Similar examples include:
- Radio Button Example (aria-activedescendant): Radio button group using
aria-activedescendant
for managing keyboard focus.
Example Start
Pizza Crust
Regular crust
Deep dish
Thin crust
Pizza Delivery
Pickup
Home Delivery
Dine in
Radio group Widget Implementation Information
Implementation Notes
- Uses CSS attribute selectors for synchronizing
aria-checked
state with the visual state indicator. - Uses CSS
:hover
and:focus
psuedo selectors for styling visual keyboard focus and hover.
Keyboard Support
Key | Function |
---|---|
Tab |
|
Space |
|
Down arrow |
|
Up arrow |
|
ARIA Roles, Properties and States
Role | Attributes | Element | Usage |
---|---|---|---|
radiogroup |
div |
|
|
aria-labelledby="[IDREF]" |
div |
|
|
radio |
div |
|
|
tabindex="-1" |
div |
|
|
tabindex="0" |
div |
|
|
aria-checked="false" |
div |
|
|
aria-checked="true" |
div |
|
Javascript and CSS Source Code
- CSS: radio.css
- Javascript: radioGroup.js
- Javascript: radioButton.js
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>
<script type="text/javascript">
var rg1 = new RadioGroup(document.getElementById('rg1'));
rg1.init();
var rg2 = new RadioGroup(document.getElementById('rg2'));
rg2.init();
</script>