Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Accessibility – ARIA Roles and Labels | HTML Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. HTML Course

Lesson 9 of 55

·HTML

Accessibility – ARIA Roles and Labels

10 min

Course progress16%

What you'll learn

Keep these ideas in mind as you work through the lesson.

5 points
  • Core ARIA attributes (`role`, `aria-label`, `aria-describedby`, `aria-live`)
  • When to use ARIA vs. native semantic elements
  • Improving screen‑reader experience with live regions and state attributes
  • Testing with screen readers and automated accessibility tools
  • Common pitfalls: using ARIA to compensate for poor semantics

Making HTML Accessible

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>

Core ARIA attributes

  • 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.

When to use ARIA

  • Prefer native HTML elements (<button>, <nav>, <dialog>) because they are automatically accessible.
  • Use ARIA only when building custom widgets that need additional semantic information.

Practical example – Custom toggle button

<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.


Quick checklist for ARIA

  1. Native element exists for the UI pattern? ✅
  2. ARIA role added only when needed? ✅
  3. Accessible name provided (aria-label or visible text)? ✅
  4. State attributes (aria-expanded, aria-pressed) kept in sync with UI? ✅
  5. Tested with an accessibility validator? ✅

If any answer is “no”, refactor your markup now.

Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from HTML CourseBrowse activities
Previous lessonForm Validation – Built‑in ConstraintsContinue to lesson 10Multimedia – Audio and VideoBack to HTML Course curriculum