Overview
Accessible Rich Internet Applications ARIA defines attributes and roles that make web content more accessible by providing information that can be used by assistive technologies.
There are around 50 defined ARIA attributes and around 48 roles, but only a handful of these are commonly used. In general, whenever native HTML elements and their attribute can be used instead, those are preferred.
Commonly Used ARIA Attributes
aria-controls
Apply this to elements that users can interact with to modify the
appearance of other elements, including changing whether they are visible.
For example, this can be applied to a button element
when clicking it toggles the visibility of a p element.
aria-describedby
Apply this to elements whose content describes another element.
This differs from the attributes aria-label and aria-labelledby
which provide a short name for an element.
This attribute identifies another element that provides supplementary,
often longer, instructions, context, or validation messages.
It acts like an accessible tooltip or hint.
For example:
<button aria-describedby="launch-desc">Launch</button>
<p id="launch-desc">
Click the "Launch" button to launch missiles that may cause destruction.
</p>
This attribute can refer to multiple elements. For example:
<input type="password" aria-describedby="password-error password-hint" />
<!-- This element is perhaps always visible. -->
<p id="password-hint" class="hint-text">
The password must be 8-20 characters long and include one special character.
</p>
<!-- This element is perhaps only visible after invalid input is entered. -->
<div id="password-error" role="alert" style="display: none;">
The password must include a special character.
</div>
aria-disabled
Apply this to elements that are not form controls, but play the role of one,
and should be considered to be in a disabled state.
Typically it is best to use form elements like button and input,
and use their disabled attribute instead of the aria-disabled attribute.
aria-expanded
Apply this to elements that control whether their content or
the content of another element is expanded/displayed or collapsed/hidden.
When expanded, use aria-expanded="true".
When collapsed, use aria-expanded="false".
If the element controls the content of another element,
also include the aria-controls attribute to identify that relationship.
One example of using this is rendering a tree of data where
users can click a parent node to toggle whether its child nodes are visible.
The elements representing parent nodes
should include the aria-expanded attribute.
aria-hidden
Apply this elements that should be hidden from assistive technologies. Examples include:
- purely decorative content, such as icons or images
- offscreen or collapsed content, such as menus
aria-invalid
Apply this to input elements using JavaScript after validation code
determines whether the value is valid.
Possible attribute values include “true”, “false”, “grammar”, and “spelling”.
Any other values are treated the same as “true”.
When the input value is valid, this attribute can be remove,
or its value can be set to “false” or an empty string.
aria-label
Apply this to elements to give then an accessible name.
For example, a button element that deletes some associated data
and only contains a trash can icon,
can have the attribute aria-label="delete".
Typically the label element is used in place of this
when displaying the accessible name is desired.
aria-labelledby
Apply this to elements whose accessible name is provided by another element. The other element does not need to be visible.
aria-required
Apply this to elements that play the role of a form control
and require the user to enter/select a value.
When the elements input, select, and textarea require a value,
use the required attribute instead of the aria-required attribute.
Roles
ARIA supports two categories of roles.
“Landmark” roles are applied to elements that contain a section of the page.
“Widget” roles are applied to elements not normally used as
form controls but are configured to behave like them.
For example, they make it possible implement button-like functionality
using a div element in an accessible way.
It’s best to use the native HTML form control elements when possible.
Landmark Roles
-
bannerApply this to an element that contains the main header content. Typically the
headerelement is used instead of applying this role to some other kind of element. -
complementaryApply this to elements that contain information that supports the main content, such as a sidebar. Typically the
asideelement is used instead of applying this role to some other kind of element. -
contentinfoApply this to elements that contain document metadata such as copyright and author information.
-
mainApply this to a single element that holds the main content of the page. Typically the
mainelement is used instead of applying this role to some other kind of element. -
navigationApply this to elements contain navigational links such as menu or table of contents. Typically the
navelement is used instead of applying this role to some other kind of element. -
searchApply this to elements that contain search functionality. Typically the
searchelement is used instead of applying this role to some other kind of element.
Widget Roles
-
alertApply this to elements that
-
buttonApply this to elements that have been configured to act as buttons. Typically the
buttonelement is used instead of applying this role to some other kind of element. -
checkboxApply this to elements that have been configured to act as checkboxes. Typically the
inputelement with atypeattribute of “checkbox” is used instead of applying this role to some other kind of element. -
dialogApply this to elements that represent a modal window or alert that requires user interaction and temporarily blocks access to other parts of the page. Typically the
dialogelement or adivelement with apopoverattribute is used instead of applying this role to some other kind of element. -
tabApply this to elements that controls the visibility of a tab pane.
-
tablistApply this to elements that contain a set of “tab” elements.