Lesson 9 of 55
HTMLAccessibility – ARIA Roles and Labels
10 min
Course progress16%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 9 of 55
HTML10 min
Keep these ideas in mind as you work through the lesson.
ARIA (Accessible Rich Internet Applications) adds semantics to custom widgets when native elements fall short.
<div role='navigation' aria-label='Main navigation'>
<ul>
<li><a href='#'>Home</a></li>
<li><a href='#'>About</a></li>
</ul>
</div>
role – Defines the widget type (navigation, button, dialog, alert).aria-label – Provides an accessible name when visible text isn’t sufficient.aria-describedby, aria-controls, aria-expanded – Communicate relationships and state for dynamic components.<button>, <nav>, <dialog>) because they are automatically accessible.<button id='menuToggle' aria-expanded='false' aria-controls='mainMenu'>Menu</button>
<nav id='mainMenu' hidden>
…
</nav>
<script>
const btn = document.getElementById('menuToggle');
const menu = document.getElementById('mainMenu');
btn.addEventListener('click', () => {
const open = btn.getAttribute('aria-expanded') === 'true';
btn.setAttribute('aria-expanded', !open);
menu.hidden = open;
});
</script>
Tip: Validate ARIA usage with tools like axe, WAVE, or the built‑in Chrome DevTools Accessibility panel to catch common mistakes.
aria-label or visible text)? ✅aria-expanded, aria-pressed) kept in sync with UI? ✅If any answer is “no”, refactor your markup now.