ARIA is a set of attributes that add meaning to the HTML for assistive technology.
It is genuinely useful, and it is also the easiest way to build an inaccessible page, because ARIA can override what the browser already knows correctly.
The guiding rule is short. Use the native HTML first, and add the ARIA only where the HTML has no answer.
The previous lesson in this module covered "What Are header, nav, main, article and footer Really For?", and the next lesson in this module is about "How Does Keyboard Focus Order Shape Usability?".
What is ARIA, in one sentence?
ARIA, which stands for Accessible Rich Internet Applications, is a vocabulary of roles, states, and properties that tells assistive technology what a thing is, and what it is doing.
A role says what an element is, such as "this is a button". A state says what is true right now, such as "this is expanded". And a property gives extra information, such as "this controls that panel".
<!-- role: what it is -->
<div role="button" tabindex="0">Save</div>
<!-- aria-expanded: what is true right now -->
<button aria-expanded="false" aria-controls="panel">Details</button>
<!-- aria-label: an accessible name -->
<button aria-label="Close dialog">×</button>The attributes work on the elements that the browser already understands.
The aria-expanded on the button above is the interesting one. The button is a real button, so it already works with a keyboard and announces itself as a button, and the ARIA attribute adds the state that a screen reader user needs in order to know whether the panel is open.
Why is "do not use ARIA" the first rule?
Because the native HTML already carries the semantics.
A real <button> is focusable, it responds to Enter and Space, it appears in the accessibility tree as a button, and it is announced as one, all without a line of code.
A <div role="button"> has to be given a tabindex to be focusable, a key handler to respond to Enter and Space, and careful CSS to show a focus ring, or it is a worse button than the element that already exists.
<!-- native: everything works, for free -->
<button type="button">Save</button>
<!-- ARIA: you now own focus, keyboard and state -->
<div role="button" tabindex="0" onclick="save()">Save</div>The ARIA is for the cases that the HTML does not cover. There is a custom widget, there is a live region, and there is a relationship between two elements that is not otherwise expressed.
The most common real need is the disclosure widget. That is a button that shows and hides a panel, where a plain button needs one extra attribute to say whether the panel is open.
Which ARIA attributes cover most needs?
The aria-label gives an element an accessible name when there is no visible text. You use it for the icon-only buttons.
The aria-labelledby points at the id of the element that names it, for the cases where the visible label is somewhere else on the page.
The aria-describedby points at a description that is additional to the name, such as a hint under a field.
The aria-expanded, the aria-selected, and the aria-checked describe the current state of a widget, and they have to be kept in step with the real state.
The aria-hidden="true" hides an element from assistive technology, and that is useful for an icon that repeats the adjacent text.
The role="alert" and the aria-live announce the content that changes without a page reload.
The live region pattern is the one worth knowing early, because it is how you tell a screen reader user that something happened without them needing to go looking for it.
<div id="status" role="status" aria-live="polite"></div>
<script>
document.querySelector('#status').textContent = 'Saved successfully';
</script>The live region has to exist on the page before the message goes into it.
If you create the element and fill it in at the same moment, then many screen readers will not announce it, because they were not watching yet.
What are the common mistakes?
There are three mistakes that account for most broken ARIA.
The first is a role that contradicts the element. Putting the role="button" on a link, or the role="heading" on a paragraph, creates a mismatch between what the user sees and what they hear.
The second is a stale state. An aria-expanded="false" that is never updated when the panel opens is worse than having no ARIA at all, because it actively misleads.
The third is redundancy. The <button role="button"> adds nothing, and it can confuse a screen reader into announcing it twice.
<!-- redundant and confusing -->
<button role="button" aria-label="Save">Save</button>
<!-- contradictory -->
<a href="/docs" role="button">Documentation</a>
<!-- right -->
<a href="/docs">Documentation</a>There is one more rule. A visible label and an ARIA name have to agree.
If a button says "Save" and the aria-label says "Save changes", then a screen reader user hears "Save changes, button" while a sighted user sees "Save".
The mismatch breaks the voice of the control too, because the users of voice control say what they see.
When is ARIA the wrong tool?
The ARIA is a translation layer. It tells a screen reader what a control that is built from ordinary elements really is, and it is the right answer when the HTML that you have cannot express the semantics that you need.
It is the wrong answer when better HTML would do the same job with less code and fewer ways to go wrong.
There are three cases where the ARIA earns its place.
There is a custom tab widget, where the role="tablist", the role="tab", and the aria-selected attributes tell the user agent that these are tabs, and which one is the current one.
There is a live region, such as the aria-live="polite", which announces a message that changes without the user moving the focus.
And there is the aria-label on a control whose visible label is missing or ambiguous, for instance an icon-only button.
And there are three cases where it does not.
Adding the role="button" to a <button> is pure noise.
Marking a heading with the role="heading" adds nothing to a real <h2>.
And the aria-hidden="true" on a container that is full of visible text hides the content that a sighted user can read and a screen reader user cannot. That is a bug and not a feature.
<!-- redundant: the element already has the role -->
<button role="button" type="button">Save</button>
<!-- necessary: the icon alone needs a name -->
<button type="button" aria-label="Close dialog">
<span aria-hidden="true">×</span>
</button>Notice the second example. The visible cross is hidden from the screen reader with the aria-hidden, and the button gets its name from the aria-label.
That pairing is the standard pattern for icon buttons, and it keeps the accessible name and the visual content from fighting each other.
The habit worth forming is this one. You reach for the native element first, and you reach for the ARIA only when the native element genuinely cannot express what you need.
Quick reference
- The native HTML first, and the ARIA only where the HTML has no answer.
- The ARIA never adds the keyboard behaviour. A
role="button"div is not a button. - You keep the states in step with the reality, and you never contradict the visible text.
- You do not add a role to an element that already has the right one.
- A live region has to be in the page before the message arrives.
- You use the
aria-labelfor the icon-only controls, and you use thearia-labelledbyto point at an existing visible label.
Try it yourself: add a disclosure button to a page. That is a real button that shows and hides a panel, with the aria-expanded and the aria-controls, and you update the attribute when it opens.
Then you open the accessibility tree, and you confirm that the state is exposed. Next, you remove the attribute, and you notice how much less a screen reader user would know.