Skip to content
tezvyn:
Menu

Announcing status messages with ARIA live regions

Source: interviewMediumHow cards are made

Summary

Announcing dynamic updates without stealing focus.

Key points

use a live region with aria-live polite or role status, ensure it exists in the DOM beforehand, and insert text to trigger announcement.

Watch out for

moving focus to the message.

What's really being asked

This probes knowledge of ARIA live regions: how to make screen readers announce content that changes after page load without yanking the keyboard focus away from the user current task.

The full answer

The mechanism is a live region. Wrap the message area in an element with aria-live set to polite for non-urgent updates or assertive for urgent ones, or use the shorthand roles: role status implies polite and role log also exists, while role alert implies assertive. For a save confirmation, polite or role status is right because it should wait until the screen reader finishes the current utterance. A critical detail: the live region container must be present in the DOM before you change its contents, because screen readers watch existing live regions for mutations. You then set or append the text, which triggers the announcement. Focus stays put. Keep messages short and avoid rapid repeated updates that flood the user.

The mistakes people make

Moving focus to the toast defeats the requirement and disrupts the task. Creating both the live region and its text in one insertion can mean the screen reader never registered the region, so nothing is announced. Using assertive for routine confirmations is rude because it interrupts. Hiding the region with display none stops some screen readers from announcing it.

What usually comes next

When do you choose alert versus status? How do aria-atomic and aria-relevant change what gets read? Why do some announcements fail intermittently and how do you debounce or re-trigger them? How do toast libraries handle this?

A concrete example

After saving a profile, a visually hidden div with role status already in the DOM receives the text Your profile has been saved. The screen reader announces it after finishing whatever it was reading, the user keeps editing the next field, and focus never moved. For a failed save you would instead use role alert so it interrupts immediately.

Interview question

A toast says 'Profile saved.' Using a live region, why must the live region element exist in the DOM before the message text is inserted?

  • a.Because screen readers watch existing live regions for content changesCorrect
  • b.Because aria-live cannot be combined with role status
  • c.Because aria-live only works on elements rendered server-side
  • d.Because the region must be focused before it can announce
Why?

Screen readers monitor live regions already present in the DOM for mutations. Inserting the region and its text together can mean the change is missed. Live regions announce without focus, and aria-live and role status work together.

Just read this? Test yourself on what you have been reading.

Read the original → developer.mozilla.org

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.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on accessibility — each one lists the topics its interview covers.

See open roles