liveAnnouncer()
Read updates aloud to screen readers.
Try the example
Add a sample item to the basket. The count updates visually and the same useful update is announced politely to a screen reader without moving your focus.
Illustrative basket. No purchase is made.
Add it to your project
- Copy the HTML. Place the markup inside the component where this behavior belongs. The preview’s visual classes are website styles; use your own design system.
- Connect the behavior. Copy the JavaScript tab and call its exported
mount(element)after your component’s elements exist. Replace simulated delays and data operations with your own application code. - Clean up. Call the returned cleanup when the component unmounts. It aborts the example’s listeners and releases the helper’s timers, observers or state.
API and lifecycle
Create a persistent empty live region before updates occur. announce(message) writes a text update after a short delay. The default priority is polite; include the visually hidden CSS so the region remains accessible.
- Interface
priority, parent; announce/destroy; include CSS- Lifecycle
- Reuse the instance for related updates. destroy() cancels the pending announcement and removes the live-region element.
Accessibility and safety
Implementation notes
Initialize after the DOM is available. Keep native controls and keyboard interactions intact; release listeners and timers on unmount.
Use assertive only for urgent interruptions. Avoid duplicate announcements of visible focused errors, and do not move focus to routine status updates.
What to check
Use a screen reader to check one useful announcement per update. Confirm routine updates do not interrupt typing or move keyboard focus.