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, Live Region | HTML Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. HTML Course

Lesson 28 of 55

·HTML

Accessibility – ARIA Roles, Live Regions, and Keyboard Navigation

12 min

Course progress51%

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

Deep Dive into ARIA

When native HTML cannot convey the needed semantics, ARIA attributes fill the gap.

Modal dialog example

<div id='myModal' role='dialog' aria-modal='true' aria-labelledby='modalTitle'>
  <h2 id='modalTitle'>Subscribe</h2>
  <form>
    <label for='email'>Email:</label>
    <input type='email' id='email' required />
    <button type='submit'>Send</button>
  </form>
  <button aria-label='Close' onclick='closeModal()'>&#x2716;</button>
</div>
  • role='dialog' tells assistive tech it’s a modal.
  • aria-modal='true' traps focus inside the dialog.
  • aria-labelledby links the dialog to its heading for a clear name.

Live region example

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

JavaScript can update #status with messages that screen readers will announce without interrupting the user.

Keyboard navigation best practices

  • Ensure all interactive elements are reachable via Tab.
  • Provide a visible focus outline (:focus { outline: 2px solid #5b9dd9; }).
  • Allow closing modals with Esc and return focus to the element that opened the modal.
  • Keep the tab order logical; avoid tabindex values higher than 0 unless absolutely necessary.

ARIA for custom widgets

  • role='button' for <div> or <span> acting like a button.
  • aria-pressed for toggle buttons.
  • aria-expanded for expandable sections (accordions, menus).
  • aria-controls to indicate which element is being controlled.

Quick checklist for ARIA and keyboard

  1. Native elements used where possible? ✅
  2. ARIA roles 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 a screen reader and accessibility validator? ✅

If any answer is “no”, refactor your markup before moving on.

Tip: Run the axe Chrome extension on your pages; it highlights missing ARIA attributes, insufficient color contrast, and focus‑order issues.

Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from HTML CourseBrowse activities
Previous lessonProgressive Enhancement – Feature DetectionContinue to lesson 29Internationalization – `lang` Attribute and Text DirectionBack to HTML Course curriculum