ARIA Attributes in HTML

ARIA attributes in HTML are used to improve accessibility when native HTML alone cannot describe a user interface clearly. ARIA stands for Accessible Rich Internet Applications. It provides roles, states, and properties that assistive technologies can use to understand custom widgets, dynamic content, menus, tabs, dialogs, alerts, and complex interactions.

ARIA is powerful, but it must be used carefully. The first rule is simple: use native HTML whenever possible. A real button is better than a div with ARIA pretending to be a button. A real label is better than an ARIA label when visible label text is possible. ARIA should improve semantics, not hide poor HTML structure.

What is ARIA in HTML

ARIA adds extra accessibility information to HTML elements. It can define what an element is, what state it is in, what label it has, what content it controls, or whether live content has changed. Assistive technologies can read this information and announce it to users.

<button aria-expanded="false" aria-controls="menu">
  Menu
</button>

<nav id="menu" hidden>
  <a href="/">Home</a>
  <a href="/about/">About</a>
</nav>

In this example, aria-expanded tells whether the menu is open or closed, and aria-controls points to the controlled menu element. JavaScript should update aria-expanded when the menu state changes.

ARIA Roles, States and Properties

ARIA TypePurposeExample
RoleDefines what an element representsrole="dialog"
StateDescribes changing conditionaria-expanded="true"
PropertyAdds relationship or label informationaria-label="Close"
Live regionAnnounces dynamic updatesaria-live="polite"

Roles describe the type of element or widget. States describe things that can change, such as expanded, selected, checked, or hidden. Properties describe extra information, such as labels, descriptions, and relationships.

aria-label

The aria-label attribute gives an accessible name to an element when there is no visible text label. It is common for icon-only buttons, search fields, and compact controls. Use it when visible text is not practical, but prefer visible labels when possible.

<button type="button" aria-label="Close dialog">
  Ã-
</button>

<input type="search" name="q" aria-label="Search tutorials">

The label should describe the action or purpose. For an icon button, Close dialog is better than X. For a search field, Search tutorials is clearer than Search if the page has multiple search areas.

aria-labelledby

The aria-labelledby attribute points to another element that provides the accessible name. It is useful when visible text already exists somewhere else on the page and should label a region, dialog, or control.

<h2 id="settings-title">Account Settings</h2>

<section aria-labelledby="settings-title">
  <p>Update your account preferences.</p>
</section>

This avoids repeating label text inside an aria-label. It also keeps the accessible name connected to visible content, which is usually easier to maintain.

aria-describedby

The aria-describedby attribute points to extra descriptive text. It is often used for help text, validation messages, password rules, warnings, or field instructions.

<label for="password">Password</label>
<input
  type="password"
  id="password"
  name="password"
  aria-describedby="password-help">

<p id="password-help">Use at least 8 characters.</p>

The label gives the field name, while the description gives additional guidance. This separation is useful because the user hears both the purpose and the rule.

aria-expanded and aria-controls

The aria-expanded attribute tells whether a collapsible element is open or closed. The aria-controls attribute can point to the element being controlled. These attributes are common in menus, accordions, dropdowns, and disclosure widgets.

<button aria-expanded="false" aria-controls="faq-answer">
  What is HTML?
</button>

<div id="faq-answer" hidden>
  HTML is the standard markup language for web pages.
</div>

When JavaScript opens the answer, it should remove hidden and update aria-expanded to true. If the visual state changes but the ARIA state does not, assistive technology users may receive wrong information.

aria-hidden

The aria-hidden attribute hides content from assistive technologies. It should be used carefully. It is useful for decorative icons or duplicate visual content, but it can be dangerous if applied to important text or focusable controls.

<span aria-hidden="true">â~.</span>
<span>Featured tutorial</span>

Do not put aria-hidden="true" on a parent element that contains buttons, links, inputs, or important text. The content may remain visible visually but become unavailable to screen reader users.

aria-live

The aria-live attribute is used for dynamic content updates. It tells assistive technologies that content changes should be announced. This is useful for form errors, status messages, cart updates, search result counts, and background operation feedback.

<p id="status" aria-live="polite"></p>

<script>
  document.querySelector("#status").textContent = "Profile saved successfully.";
</script>

Use polite for normal updates that can wait. Use assertive only for urgent updates because it may interrupt the user. Too many live announcements can become annoying and confusing.

ARIA Does Not Add Behavior

ARIA changes how elements are described to assistive technologies, but it does not automatically add keyboard behavior, mouse behavior, focus management, or visual styling. If you create a custom dropdown with ARIA roles, you must also implement keyboard controls correctly.

No ARIA is better than bad ARIA.

Bad ARIA can make a page worse by giving wrong information. For example, setting aria-expanded="true" while a menu is visually closed creates a mismatch. Always keep ARIA state synchronized with the real UI state.

Native HTML vs ARIA

NeedBest First ChoiceAvoid
Clickable action<button><div role="button"> without keyboard support
Navigation<a href>Button used as a link
Form label<label>ARIA label when visible label is possible
Checkbox<input type="checkbox">Custom checkbox without keyboard behavior
DialogNative dialog or carefully built dialog patternUnmanaged popup with no focus handling

Use ARIA when native HTML cannot fully describe the pattern. Do not use ARIA to replace simple semantic elements that already work.

aria-current and aria-selected

The aria-current attribute identifies the current item in a set, such as the current page in navigation or the current step in a process. It is different from aria-selected, which is used for selectable widgets such as tabs, listboxes, and grid options.

<nav>
  <a href="/" aria-current="page">Home</a>
  <a href="/html/">HTML</a>
</nav>

Use aria-current="page" for the active navigation link that represents the current page. Do not use it simply for hover states or visual styling. It should describe the user’s current location or current item.

ARIA for Alerts and Status Messages

Status messages are common in modern interfaces. A save button may show Profile saved, a cart may show Item added, or a form may show three errors found. ARIA live regions help announce these changes without forcing the user to search the page manually.

<div role="status" aria-live="polite" id="save-status"></div>

For normal status updates, use polite announcements. For urgent errors that require immediate attention, assertive announcements may be used carefully. Too many assertive messages can interrupt screen reader users and make the interface stressful.

Testing ARIA

ARIA should be tested, not guessed. At minimum, check keyboard behavior, focus order, visible state, and whether ARIA attributes update when the UI changes. Browser developer tools can inspect accessible names and roles. Screen reader testing gives better confidence for complex widgets.

If ARIA adds complexity without a clear benefit, remove it and return to native HTML. The goal is not to use more ARIA. The goal is to provide accurate meaning and usable interaction.

ARIA and Focus Management

Many ARIA patterns need focus management. A dialog should move focus into the dialog when opened and return focus to the opening button when closed. A menu should have logical keyboard movement. A tab interface should make the active tab and active panel clear. ARIA names the pattern, but JavaScript must manage interaction.

If focus stays behind a modal or moves unpredictably, the interface becomes difficult for keyboard and screen reader users. This is why custom widgets should be built from tested patterns instead of improvised markup.

Useful ARIA Attributes Summary

AttributeCommon Use
aria-labelAccessible name without visible label
aria-labelledbyName from existing visible element
aria-describedbyConnect help text or error text
aria-expandedOpen or closed state
aria-controlsRelationship to controlled element
aria-hiddenHide decorative or duplicate content from assistive tech
aria-liveAnnounce dynamic updates

These attributes cover many real cases. Learn them with examples instead of adding them randomly. Every ARIA attribute should answer a clear question about name, role, state, relationship, or live updates.

If you cannot explain why an ARIA attribute is present, it probably should not be there. Correct ARIA is intentional, minimal, and synchronized with the actual interface.

That discipline keeps complex components understandable for every user across different assistive tools and browsers too.

Common ARIA Mistakes

  • Using ARIA where native HTML would be better.
  • Adding roles without keyboard behavior.
  • Forgetting to update aria-expanded, aria-selected, or aria-checked when state changes.
  • Using aria-hidden on important content.
  • Writing unclear aria-label text.
  • Creating custom widgets without testing with keyboard navigation.

ARIA attributes are useful for complex interfaces, but they require discipline. Start with semantic HTML, add ARIA only where it improves meaning, keep ARIA states synchronized with the visible interface, and test keyboard behavior. Correct ARIA helps users; incorrect ARIA creates confusion.

Should I use ARIA everywhere?

No. Use semantic HTML first. Add ARIA only when native HTML cannot provide the needed accessibility information.

Does ARIA make divs work like buttons?

No. ARIA can describe a role, but it does not automatically add keyboard behavior or button functionality.


Continue learning HTML in order
Follow the topic sequence with the previous and next lesson.