Accessible toasts with ARIA live regions
announcing dynamic content without moving focus.
a persistent live region, polite vs assertive by urgency, role status or alert, content injected after mount.
moving focus to the toast or creating the region at announce time.
What's really being asked
This checks whether you understand live regions, the mechanism for announcing dynamic content to assistive tech without changing focus, and their timing pitfalls.
The full answer
The core idea is a live region: an element already in the DOM whose content changes are automatically announced by screen readers, no focus move required. Render the toast container, or a dedicated visually present announcer, on mount so it exists before any message; then update its text content when a toast fires. Choose politeness by urgency: aria-live polite, or role status which is implicitly polite, for ordinary notifications so the announcement waits for a pause; aria-live assertive, or role alert which is implicitly assertive, only for urgent, time-sensitive messages because it interrupts. Critically, do not move focus to the toast, which would yank keyboard users out of their task; the whole point is a non-disruptive announcement. Handle timing: queue or debounce rapid messages so a new one does not overwrite the previous before it is read, and keep messages on screen long enough or provide a persistent log.
The mistakes people make
Creating the live region element at the moment the toast appears, which many screen readers will not announce because the region was not present to observe. Using assertive for everything, constantly interrupting users. Moving focus to the toast. Auto-dismissing so fast the message is gone before it is read.
What usually comes next
When do you use assertive versus polite. Why must the region pre-exist. How do you handle a flood of notifications.
A concrete example
A persistent div with role status sits in the layout; when a save succeeds, the toast text Saved is written into it and a screen reader announces Saved without focus moving, while a critical error toast uses role alert to interrupt immediately, and both leave the user's keyboard position untouched.
Interview question
Why should a toast component render its ARIA live region in the DOM before any message appears, rather than creating it when the toast fires?
- a.It allows the toast to steal focus more smoothly
- b.It reduces the component's JavaScript bundle size
- c.Live regions only work inside a focused element
- d.Screen readers must be observing the region beforehand to reliably announce later content changesCorrect
Why? this is the answer
Assistive tech announces changes to regions it is already observing; a region inserted at announce time is often missed. Bundle size is irrelevant, toasts should never steal focus, and live regions do not require focus.
Just read this? Test yourself on what you have been reading.
Read the original → developer.mozilla.org
- #accessibility
- #aria
- #live-regions
- #notifications
- #design-systems
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on accessibility — each one lists the topics its interview covers.
See open roles