Ugrás a fő tartalomra
← 📄 HTML & the platform·Modul A5 · Lecke 7
FeladatBuild: <p id='out' aria-live='polite'></p> + <button id='go'>Run</button>. JS: on button click, set #out's textContent to 'Saved!'. Auto-click #go so the test sees the update.

ARIA-live: dinamikus változások bejelentése

100 XP8 min
Elmélet

When content changes WITHOUT a page reload

A user submits a form via fetch. The response appears in a <div>. Sighted users see it. Screen-reader users DON'T — the DOM changed silently. To make the change audible, mark the container with aria-live:

<div id="status" aria-live="polite">
  <!-- when JS injects text here, the screen reader announces it -->
</div>

polite vs assertive

  • `aria-live="polite"` — announces during a natural pause in screen-reader speech. Use for non-urgent feedback ("Saved.", "5 items found").
  • `aria-live="assertive"` — interrupts whatever the screen reader is reading right now. Use ONLY for critical errors ("Session expired.", "Payment failed.").

99% of cases want polite. Reach for assertive when missing the message would harm the user.

Common gotchas

  • The aria-live region must be in the DOM BEFORE the content is added. Adding a new <div aria-live="polite">FYI</div> to the DOM doesn't trigger an announcement.
  • Don't put two screen-reader status messages in the same region in quick succession — the second can clobber the first.
  • Clear the region between announcements (set it to empty, then to the new message). Some screen readers don't re-announce identical text.

Built-in roles that imply aria-live

  • role="status" = aria-live="polite"
  • role="alert" = aria-live="assertive"
  • role="log" = aria-live="polite" + aria-atomic="false"

So <div role="status"> is shorthand for <div aria-live="polite">.

🔒

Regisztrálj, hogy elkezdj programozni

Az elmélet mindenkinek nyitva. A szerkesztő, élő előnézet és ellenőrzés 7 napos ingyenes próbával nyílik meg — kártya szükséges, bármikor lemondható.

Regisztráció — ingyenes próba →

Minden útvonal első 10 leckéje ingyenes. Nem kell kártya.

← ElőzőKövetkező lecke →

Egy Python- vagy webes tipp naponta — emailben

Rövid, kézzel írt, spam nélkül. Egy kattintással leiratkozhatsz.