Button Examples
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.
The following command and toggle button examples demonstrate the button design pattern.
Similar examples include:
- Navigation Menu Button: A button that opens a menu of items that behave as links.
- Action Menu Button Example Using element.focus(): A button that opens a menu of actions or commands where focus in the menu is managed usingelement.focus().
- Action Menu Button Example Using aria-activedescendant: A button that opens a menu of actions or commands where focus in the menu is managed usingaria-activedescendant.
Example
This Print
 action button uses a div element.
Print Page
        This Mute
 toggle button uses an a element.
Keyboard Support
| Key | Function | 
|---|---|
| Enter | Activates the button. | 
| Space | Activates the button. | 
Role, Property, State, and Tabindex Attributes
| Role | Attribute | Element | Usage | 
|---|---|---|---|
| button | div,a | 
 | |
| tabindex="0" | div,a | 
 | |
| aria-pressed="false" | a | 
 | |
| aria-pressed="true" | a | 
 | 
Javascript and CSS Source Code
- CSS: button.css
- Javascript: button.js
HTML Source Code
<p>
  This
  <q>
    Print
  </q>
  action button uses a
  <code>
    div
  </code>
  element.
</p>
<div tabindex="0"
     role="button"
     id="action">
  Print Page
</div>
<p>
  This
  <q>
    Mute
  </q>
  toggle button uses an
  <code>
    a
  </code>
  element.
</p>
<a tabindex="0"
   role="button"
   id="toggle"
   aria-pressed="false">
  Mute
  <svg aria-hidden="true" focusable="false">
    <use xlink:href="#icon-sound"></use>
  </svg>
</a>