← Back to HTML Course | Chapter 10: Reference & Interview Prep | Lesson 7 of 20

HTML ARIA Roles

ARIA stands for Accessible Rich Internet Applications. ARIA roles and attributes are like invisible labels you add to HTML elements to help screen readers understand what each part of your page does. Think of it as adding subtitles for users who cannot see your page.

What are ARIA Roles

An ARIA role tells assistive technology what an element does. For example role=navigation tells a screen reader this is a navigation area even if it is just a div. Overusing roles on elements that already have the correct native semantics (like using role=button on an actual button tag) is unnecessary and can even cause confusion.

Note: Use semantic HTML first. Only add ARIA roles when semantic HTML cannot express the meaning you need.

Warning: Adding wrong ARIA roles is worse than adding none — it actively misleads screen reader users.

Example: What are ARIA Roles

markup
<div role="navigation">Site links here</div>

aria-label and aria-describedby

aria-label provides a text description for elements that have no visible label. aria-describedby links an element to a longer description elsewhere on the page. Using both together is common: a short aria-label for the accessible name and aria-describedby for extra supporting detail.

Note: Use aria-label on icon-only buttons so screen readers can announce their purpose.

Warning: Do not use aria-label on elements that already have visible text — it overrides the visible label for screen readers.

Example: aria-label and aria-describedby

markup
<button aria-label="Close" aria-describedby="closeHint">X</button>
<span id="closeHint">Closes this dialog</span>

aria-expanded for Toggles

aria-expanded tells assistive technology whether a collapsible element, like a dropdown menu or accordion panel, is currently open or closed, and its value should be updated dynamically with JavaScript whenever the element's state changes.

Example: aria-expanded for Toggles

markup
<button aria-expanded="false" onclick="this.setAttribute('aria-expanded', 'true')">
  Show menu
</button>

aria-live for Dynamic Content

aria-live marks a region of the page that updates dynamically without a full page reload, telling screen readers to announce the new content automatically instead of requiring the user to navigate back to it manually.

Example: aria-live for Dynamic Content

markup
<div aria-live="polite" id="status">Loading...</div>

Landmark Roles

Landmark roles like banner, main, complementary, and contentinfo mark the major regions of a page, letting screen reader users jump directly between sections instead of tabbing through every element one at a time.

Example: Landmark Roles

markup
<div role="banner">Header</div>
<div role="main">Main content</div>
<div role="contentinfo">Footer</div>
Common Mistakes
  1. Adding ARIA roles to elements that already have the correct semantic meaning.
  2. Forgetting tabindex=0 when making non-interactive elements focusable.
  3. Using aria-hidden=true on elements that contain focusable children.
Chapter Summary
  • ARIA roles help screen readers understand your page structure.
  • Use semantic HTML first and ARIA only when needed.
  • aria-label names elements that have no visible text.
  • aria-hidden hides decorative elements from screen readers.
Browser Support

ARIA attributes are supported in all modern browsers and major screen readers including NVDA, JAWS, and VoiceOver.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.