ARIA stands for Accessible Rich Internet Application. ARIA is a collection of attributes and roles that act as add-ons to complement HTML for complex web applications, particularly those built using Javascript.
It helps make the applications accessible for assistive technology that is otherwise not possible with the use of native HTML alone. Some examples are dynamic content and user controls like error messages, tool tips, live regions.
Becoming ever so popular with web developers looking to make applications accessible, ARIA if misused can cause an inaccessible experience for a user. Which is the case today, as we see code stuffed with ARIA. It helps understanding the WAI-ARIA rules, which are not easy to decipher so we have tried to explain it in simple language.
Letโs take a look at the 5 rules of ARIA below with some examples.
Table of Contents
- 1 ARIA rule # 1: Don’t use ARIA!
- 2 ARIA rule # 2 : Do not change native semantics, unless you really, really, truly have to.
- 3 ARIA rule # 3 : All interactive ARIA controls must be usable with a keyboard.
- 4 ARIA rule # 4: Don’t use role = “presentation” or aria-hidden = “true” on a focusable element.
- 5 ARIA Rule # 5: All interactive elements must have an accessible name.
- 6 Conclusion
ARIA rule # 1: Don’t use ARIA!
If you can use a native HTML element or attribute instead, then do so.
If you shouldn’t use ARIA, then when can you use it?
If it’s not possible use a native HTML element or attribute because:
- It doesn’t exist
- It can’t be styled or,
- There is no support
Here is one common example of incorrect ARIA usage, I’ve seen:
(I had to mediate an argument between a dev and a tester just last week ๐)
๐๐ฒ๐ฟ๐ฒ ๐ถ๐ ๐๐ต๐ฒ ๐๐ฎ๐บ๐ฝ๐น๐ฒ ๐ฐ๐ผ๐ฑ๐ฒ:
<a href=โ/example.com/about/โ role=โbuttonโ> Read more </a>
๐ช๐ต๐ ๐ถ๐ ๐๐ต๐ถ๐ ๐ถ๐ป๐ฐ๐ผ๐ฟ๐ฟ๐ฒ๐ฐ๐?
Role = button tells a screen reader it is a button element,
But it doesn’t provide the functionality of a button.
So they tried to “fake” it as a button by using an <a> tag.
๐ง๐ต๐ฒ ๐ฐ๐ผ๐ฟ๐ฟ๐ฒ๐ฐ๐ ๐๐ฎ๐:
<button type=โbuttonโ>Read more about ARIA </button>
๐ช๐ต๐?
<button> is a native HTML element and is perfectly accessible.
Here is a Link to ARIA cheat sheet. One of the best Iโve seen in the industry and Iโd highly advise you to refer to it when in doubt.
ARIA rule # 2 : Do not change native semantics, unless you really, really, truly have to.
For example: A developer wants to build a heading that’s a tab.
Do not do this:
<๐ต๐ฎ ๐ฟ๐ผ๐น๐ฒ=๐๐ฎ๐ฏ>heading tab</๐ต๐ฎ>
Do this:
<div ๐ฟ๐ผ๐น๐ฒ=๐๐ฎ๐ฏ><๐ต๐ฎ>heading tab</๐ต๐ฎ></div>
The Role feature: Defines what an element does.
Some roles duplicate the semantic value of HTML5 elements : nav, aside
Others describe the page structure : banner, search, tablist, tab
ARIA attributes donโt affect the web page itself.
They only provide information to screen readers.
Use ARIA wisely.
ARIA rule # 3 : All interactive ARIA controls must be usable with a keyboard.
Native HTML interactive elements are keyboard accessible.
A custom control, needs to receive focus and the user be able to activate it with:
Enter (Windows) or Return (Mac) keys, and Space key
What this means in simple terms is:
A custom control like a button for example, must work with the keyboard as a native button element would.
๐๐ผ๐บ๐บ๐ผ๐ป ๐บ๐ถ๐๐๐ฎ๐ธ๐ฒ 1
Buttons created using <span> or <div>
๐๐ผ๐ ๐๐ผ ๐ณ๐ถ๐ :
Create button using <button> or <input>
Common mistake 2:
Links created using <span> or <div>
How to fix:
Create links using <a>
Common mistake 3:
tabindex = “-1”
How to fix:
tabindex = “0”
๐ค๐๐ถ๐ฐ๐ธ ๐ป๐ผ๐๐ฒ ๐ฎ๐ฏ๐ผ๐๐ ๐๐ฎ๐ฏ๐ถ๐ป๐ฑ๐ฒ๐ :
If you create an interactive element yourself, use tabindex to make it focusable
tabindex = “0” adds focus
tabindex = “-1” removes it from the tab order
ARIA rule # 4: Don’t use role = “presentation” or aria-hidden = “true” on a focusable element.
Let’s understand the attributes first.
role=”presentation ” or role =”none” removes the ARIA semantics from the accessibility tree.
When is it used?
When an element is used for presentation only and does not have accessibility purposes.
aria-hidden is also used to hide non-interactive content from a screen reader.
When is it used?
When you want to hide elements like:
Decorative items like icons or images that have no meaning/context
Collapsed items such as menus
Duplicate content
When are the attributes used?
aria-hidden =”true” will remove the entire element from the accessibility tree.
role=”presentation ” and role=”none” will remove the meaning of the element but still expose its content to a screen reader.
ARIA Rule # 5: All interactive elements must have an accessible name.
Accessible names help assistive technology users understand how to interact with an element.
Letโs look at what interactive elements are.
Interactive elements are:
- Links
- Buttons
- Text fields
- Checkboxes
- Combo boxes
- Radio buttons
An accessible name can be generated from a native HTML element’s content:
<button> uses the content between the opening and closing tags as its accessible name </button>
The <label> in a form will pull the content associated with its input as its accessible name.
If none of these options are available, use aria-label to define the accessible name of the element:
aria-label – text that labels the element is not visible.
aria-labelledby – visible text that labels the element.
aria-describedby – additional instructions for the input to users.
Conclusion
Now we understand what ARIA is and how it is used. Weโve also seen the benefits of using native HTML to make applications accessible out-of-the-box.
My key takeaway to prevent “excessive” ARIA use is by remembering one thing:
You don’t always need to provide instructions to screen readers only.
If the instructions are important enough, provide them to every user.
That’s what makes the best user experience.