Creating Buttons using role=button
Authoring Practice Design Patten for Button
Note: When using HTML, use the <button>
element. It is recommended that authors not re-purpose other elements to create buttons.
Button Examples
The following examples are composed by a native <button>
element, a <div>
functioning as a native button, and a <span>
element that functions as a toggle button.
Type | Technique | Button | Accessibility Feature |
---|---|---|---|
Push button | div element with text |
Print Page
|
|
Toggle button | div element with text |
Mute |
|
Push button | tabindex="0" element |
Show alert |
|
Non compliant | a element with href="#" |
Show alert |
|
Keyboard Support
Key | Function |
---|---|
Space or enter | Activate or toggle button |
ARIA Roles, Properties and States
Role | Property/State | Component | Usage |
---|---|---|---|
button | span or div |
|
|
aria-pressed | span |
|
Source Code
HTML Code
HTML source code is generated by scripting using ID references.
First Example: Push button
<div role="button">
Print Page
</div>
Second Example: Toggle button
<span tabindex="0"
role="button"
aria-pressed="false">
Mute
</span>
Third Example: Push button
<a tabindex="0"
role="button"
>
Show alert
</a>
Non-compliant Example
<a href="#"
role="button"
>
Show alert
</a>