The button role should be used for clickable elements that trigger a response when activated by the user. On its own,
role="button" can make any element (e.g. <p>, <span> or <div>) appear as a button control to a screen reader. Additionally, this role can be used in combination with the
aria-pressed attribute to create toggle buttons.
<input type="button" />and
<input type="image" />) rather than the
buttonrole, as native HTML buttons are more widely supported by older user agents and assistive technology. Native HTML buttons also support keyboard and focus requirements by default, without need for additional customization.
Keyboard and focus
Buttons are interactive controls and thus focusable. If the
button role is added to an element that is not focusable by itself (such as
<p>) then, the
tabindex attributes have to be used to make the button focusable.
Buttons can be operated by both mouse users as well as keyboard users. For native HTML
<button> elements, the button's
onclick event will fire both for mouse clicks and pressing of spacebar ,while the button has focus. But if another tag is used to create a custom button, the
onclick event will only fire when clicked by the mouse cursor, even if
role="button" is used. Because of this, the developer will have to surely add a separate key event handler to the element so that the button can be triggered,even when the space key is pressed.
role="button"alone is not sufficient. It will also be necessary to add a key event handler that listens for the Space key in order to be consistent with native buttons.
An advantage of using role="button" is that it allows the creation of toggle buttons. A toggle button can have two states: pressed and not pressed. Whether a button is a toggle button or not can be indicated with the
aria-pressed attribute in addition to the
aria-pressedis not used the button is not a toggle buttton.
aria-pressed="false"is used the button is a toggle button that is currently not pressed.
is used the button is a toggle button that is currently pressed.
aria-pressed="mixed"is used, the button is considered to be partially pressed.
Buttons should always have an accessible name. For most buttons, this name will be the same as the text inside the button. In some cases, for example for icon buttons, the accessible name can be provided through an aria-label or aria-labelledby attribute.
Possible effects on user agents and assistive technology
button role is used, user agents should expose the element as a button control in the operating system's accessibility API. Screen readers should announce the element as a button and describe its accessible name. Speech recognition software should allow the button to be activated by saying "click" followed by the button's accessible name.
Example 1: A basic button
In the snippet below, a span element has been given the
button role. Because a
<span> element is used, the
tabindex attribute is required to make the button focusable and part of the tab order. Note that this snippet implies that CSS styles are provided to make the
<span> element look like a button and that
handleBtnKeyUp are event handlers that perform the button's action when clicked and when the Space key is pressed.
<span role="button" tabindex="0" onclick="handleBtnClick()" onKeyUp="handleBtnKeyUp()">Save</span>
Example 2: A toggle button
In this snippet a native HTML button is converted to a toggle button using the aria-pressed attribute. Note that the tabindex attribute needs not to be used here because the
<button> element is already focusable by default. When the button is activated, the
aria-pressed value keeps on switching between
ARIA attributes used
Related ARIA techniques
TBD: Add support information for common UA and AT product combinations