Announcing changes
Learn how a web component announces changes to screen readers: aria-live regions in shadow DOM, ariaNotify(), and when and how often to announce.
- 01Announce from a shadow rootPut a live region inside a component, check its live properties in Chrome's tree, and make sure it exists before its text changes.
- 02Use ariaNotify() with a fallbackSend a message with
ariaNotify(), pick normal or high priority, and fall back to a live region where a browser has noariaNotify(). - 03Announce the right things, onceAnnounce results that focus doesn't show, wait for a pause before speaking, and skip what a screen reader already hears.
How do web components announce changes to screen readers?
Leela is back on Leaf and Kettle's order page. We met her in lesson 13.1. She is blind, and her screen reader reads the page aloud. She finds the Sencha card and sets the quantity to 2. Then she presses Add 2.
Other customers see steam rise over the card, from lesson 12.7. Leela hears nothing new. Focus is still on the button, and the button still says Add 2 Sencha. Did it work? Should she press again?
The card has to tell her, and leave her focus where it is. How does a component do that from inside its shadow root?
Announce it. A live region is an element whose changes a screen reader reads out, wherever focus is. One inside a shadow root works, because the accessibility tree is built from the flat tree. Or call ariaNotify() with the words. It asks the screen reader to say them, with no element to change. Either way, announce only what focus doesn't already tell, and say it once.
Here is the smallest version: a button and a live region, in one shadow root.
<tea-add></tea-add><script src="tea-add.js"></script>- In the
tea-add.jstab, line 5 puts a button and an empty span in the shadow root. The span hasrole="status". - Line 6 finds the span. Lines 7 to 9 write a sentence into it on each click.
- On the page, line 1 is the tag, and line 2 loads the tab.
Click Add 2 in the result. The words appear next to the button. Lesson 13.1 read Chrome's accessibility tree: the list of what each thing on a page is, which screen readers read. Here it is before and after the click, shortened as before:
Before the click:
button "Add 2"
status, live: polite, atomic: true, relevant: additions text
After the click:
button "Add 2", focused: true
status, live: polite, atomic: true, relevant: additions text
StaticText "Added 2 cups of Sencha to your order"Line 3 is the span. Its role is status, and three live properties come with it. The first, live: polite, makes it a live region: when its text changes, a screen reader reads the change. Focus doesn't move. Lines 7 and 8 show the region after the click, with the sentence inside. Line 6 says focus is still on the button: focused: true.
At Leaf and Kettle, Meena doesn't walk to each table when an order is ready. She says it over the speaker: "Two Sencha for Leela." Leela keeps her seat and her book. The news reaches her where she is.
- In real life: Meena's voice over the speaker
- In HTML: An announcement to the screen reader
- In real life: Leela staying in her seat
- In HTML: Focus staying on the Add button
- In real life: Walking over to her table
- In HTML: Moving focus to a message
- In real life: "Two Sencha for Leela"
- In HTML: Added 2 cups of Sencha to your order
Tell screen reader users about a change that focus doesn't show. An announcement is a short message a screen reader reads out by itself, while focus stays put. A component makes one with a live region in its shadow root, or with ariaNotify(). Announce results, and say each one once.
Why it matters: WCAG's success criterion 4.1.3, Status Messages, asks for exactly this. A status message must reach assistive technology "without receiving focus". If live regions are new to you, the JavaScript lesson Keyboard & focus and Accessible React components start there. This lesson does it from inside a component.
Do live regions work inside shadow DOM?
Yes. Lesson 13.1 showed why. Chrome builds the accessibility tree from the flat tree, where each shadow tree sits in its host's place. So a region in a shadow root is in the tree like any other. The overview proved it: the status row is there, live properties and all.
Those properties say how a region speaks. Each one has an ARIA attribute of the same name:
live, fromaria-live, says when to read a change. Polite waits for a pause, like the end of a sentence. Assertive reads it at once, cutting in.atomic, fromaria-atomic, says how much to read.truereads the whole region.falsereads only the part that changed.relevant, fromaria-relevant, says which changes count. The default,additions text, counts new elements and new text.
You can write these attributes yourself. Or a role brings them. The WAI-ARIA spec gives the status role a polite, atomic region. It gives the alert role an assertive, atomic one. Try four regions, and watch the region's row:
<tea-add></tea-add><script src="tea-add.js"></script>button "Add 2", focused: true
status, live: polite, atomic: true, relevant: additions text
StaticText "Added 2 cups of Sencha to your order"The status role brings its own live properties. It's polite: it waits for a pause. And it's atomic: the whole region is read, not just the part that changed.
- Only line 5 of the
tea-add.jstab changes: the attributes on the span. - Line 2 of each tree is the region, after a click.
Both roles bring their live values, and both are atomic. aria-live alone gives a generic row that isn't atomic. Add aria-atomic="true", and it reads the whole region too.
Does atomic matter? MDN uses a clock as its example. Say it changes from 17:33 to 17:34. Without aria-atomic, a screen reader may read only "34". With it, the whole time is read. For a one-sentence message, a status is simplest. It's polite, and it reads the whole sentence.
A component can also write into a live region on the page. Manuel Matuzović shows a button in a shadow root that fills a page <output>. That works too. But a region in the component's own shadow root goes wherever the component goes.
Why does a new live region say nothing?
Here is a version that looks the same. It makes its region in the click handler, words and all:
<tea-add></tea-add><script src="tea-add.js"></script>- In the
tea-add.jstab, line 5 puts only the button in the shadow root. - On a click, lines 7 to 9 make a span with
role="status"and the words. Line 10 adds it to the shadow root.
Before the click:
button "Add 2"
After the click:
button "Add 2", focused: true
status, live: polite, atomic: true, relevant: additions text
StaticText "Added 2 cups of Sencha to your order"After the click, the tree is the same as the overview's. Before it, there's no region at all, only line 2. That difference matters. A screen reader reads changes inside the live regions it already knows. The WAI-ARIA spec says assistive technology typically conveys changes, "not the initial contents". Here the words are the region's first content. There was no change to read.
MDN gives the fix: start with an empty region, and change its text later. The most reliable place for the region is the first markup. The one exception is role="alert". The spec has an alert read when it appears, too.
A screen over Leaf and Kettle's counter shows the order being served. When the number changes, it chimes, and people look up. One morning, Ravi hangs up a second screen with 42 already on it. Nobody hears a chime. Nothing changed. The screen just arrived showing 42.
- In real life: The screen over the counter
- In HTML: A live region that's already in the tree
- In real life: The chime when its number changes
- In HTML: A screen reader reading a change
- In real life: A new screen hung up showing 42
- In HTML: A region added together with its words
- In real life: Hanging the screen before opening time
- In HTML: An empty region in the shadow root from the start
Why it matters: put the empty region in your template, or make it in the constructor. Then only change its text. Heydon Pickering gives the same advice in his Notifications chapter: leave some time between adding a region and adding its words.
Is the kit's quantity a live region?
The kit's tea-quantity shows its number in an <output>. Lesson 13.4 gave that number the name Cups, and a hint. HTML-AAM maps <output> to the status role. So is the number a live region? Check in Chrome:
<link rel="stylesheet" href="tea-kit/tokens.css"><label for="cups">Cups</label><tea-quantity id="cups"></tea-quantity><script type="module" src="tea-kit/index.js"></script>Line 2 is the label. Line 3 is the quantity, from lesson 13.4's kit. Click + once in the result. Here is the tree after that click:
StaticText "Cups"
button "One cup less"
status "Cups", live: polite, atomic: true, relevant: additions text
StaticText "2"
button "One cup more", focused: trueLine 3 is the number: status "Cups", polite and atomic. It's a live region, and the kit has no code for it. MDN notes that many browsers treat <output> as a live region. So when + changes 1 to 2, a screen reader can read the new number. Line 5 shows focus still on the + button.
Why it matters: the quantity already speaks for itself. Nothing else should announce the number again. Keep that in mind for the tea card.
What is ariaNotify()?
A live region needs an element whose text changes. Often there's no visible text to change. "Added 2 cups of Sencha" isn't written on the card. So for years, developers kept hidden live regions, just to speak. MDN calls that "inefficient and error-prone".
ariaNotify() skips the element. You call it with the words, and the browser passes them to the screen reader. Every element has the method, and so does document:
<script src="log-announcements.js"></script><tea-add></tea-add><script src="tea-add.js"></script>- On the page, line 1 loads a helper, in the
log-announcements.jstab. Line 2 is the tag, and line 3 loads it. - In the
tea-add.jstab, line 5 puts only a button in the shadow root. Lines 7 to 9 callbutton.ariaNotify()with the sentence on each click.
Click Add 2. Nothing changes on the page. Nothing changes in Chrome's tree either. It's still just button "Add 2", focused: true. But the console prints ariaNotify (normal): Added 2 cups of Sencha to your order. That line comes from the helper:
// Prints each ariaNotify() call to the console, then passes it on.
for (const type of [Element, Document]) {
const notify = type.prototype.ariaNotify;
if (!notify) continue;
type.prototype.ariaNotify = function (message, options = {}) {
console.log(`ariaNotify (${options.priority ?? "normal"}): ${message}`);
return notify.call(this, message, options);
};
}- Line 2 goes through
ElementandDocument, the two places the method lives. - Line 3 keeps the browser's own method. Line 4 skips a browser that has none.
- Lines 5 to 8 put a wrapper in its place. Line 6 prints the priority and the words. Line 7 calls the real method, so the announcement still goes out.
You can't hear a screen reader in the result. And ariaNotify() gives nothing back:
const result = document.ariaNotify("Your order is saved");
console.log(result);Line 1 calls it on the document. Line 2 prints undefined. The ARIA Notify explainer says the call has no effects a page can see. So it can't reveal that someone uses a screen reader. A wrapper like the helper is the easy way to check what a component asks for. This lesson's own test wraps the method the same way.
The now-serving screen can only show numbers. For other news, Meena picks up the speaker's microphone and says it: "Leela, your Sencha is on the order." Nothing is written anywhere. The screen still shows the numbers.
- In real life: Meena's microphone
- In HTML:
ariaNotify() - In real life: The words she says
- In HTML: The message string
- In real life: No screen to change
- In HTML: No element whose text changes
- In real life: The screen, still used for order numbers
- In HTML: Live regions, still used for visible text that changes
The method is a standard now. The ARIA group added it to the WAI-ARIA spec in February 2026, in pull request 2577. Here is its whole shape:
- You call
ariaNotify(announcement), orariaNotify(announcement, { priority }). It returnsundefined. priorityis the only option. It's"normal", the default, or"high".- Called on an element, the words take that element's language: its
lang, or its nearest ancestor's. Called ondocument, they take the page's. - If the element is left out of the accessibility tree, nothing is sent. The spec's list includes
display: none,visibility: hidden, and thehiddenattribute. - A frame can use it, unless the page turns the
aria-notifypermissions policy off. Then each call fails without a word.
Core-AAM sets those same steps for browsers. So call the method on an element that's shown, like the button the reader just pressed. MDN adds that browsers ignore elements with no meaning, like <body>. Chrome ignores the <tea-add> host as uninteresting, so it has no row in the tree. The button has one.
Normal or high priority?
MDN says a normal message is read after whatever the screen reader is saying now. A high one is read at once, cutting in. It compares them to aria-live="polite" and aria-live="assertive". It adds that live region announcements come before ariaNotify() ones.
Think of a waiter. Most news waits until you finish your sentence. "Your card was declined" doesn't. Here is a button with a limit of 6 cups:
<script src="log-announcements.js"></script><tea-add></tea-add><script src="tea-add.js"></script>- In the
tea-add.jstab, line 7 counts the cups in the order. - Line 9 checks whether 2 more would pass 6. If so, line 10 calls
ariaNotify()withpriority: "high", and line 11 stops. - Otherwise, line 13 adds 2, and line 14 announces the new total, with the default priority.
Click Add 2 four times. The console prints three normal lines. Then it prints ariaNotify (high): Sorry, only 6 cups per order. The first three are news Leela can hear at a pause. The fourth is an error she needs now.
What if a browser has no ariaNotify()?
ariaNotify() works in Chrome 141, Firefox 150, and Safari 27 and later. It became Baseline newly available on September 14, 2026, web-features says. Older browsers don't have it. Calling a missing method throws a TypeError. So check first, and keep a live region for the rest:
<!-- ariaNotify() as the browser has it --><script src="log-announcements.js"></script><tea-add></tea-add><script src="tea-add.js"></script>Before the click:
button "Add 2"
After the click:
button "Add 2", focused: true
Console:
ariaNotify (normal): Added 2 cups of Sencha to your orderLine 1 of the tab finds ariaNotify(), so the span gets no role. A click calls ariaNotify() on the button, and the console shows it. The tree never changes.
- In the
tea-add.jstab, line 1 checks once:"ariaNotify" in Element.prototype. It'struewhere the browser has the method. - Line 7 puts the button and an empty span in the shadow root.
- Line 10 gives the span
role="status"only when the method is missing. That happens as the element is made. So the region exists before its text changes. - On a click, line 13 calls
ariaNotify(). Or line 14 writes the words into the region. - On the page, only line 1 changes. Without
ariaNotify(), it deletes the method from both places, like an older browser.
With the method, the tree never changes, and the console shows the call. Without it, the status row is there before the click, and holds the words after it. Nothing is printed, because the helper had nothing to wrap.
MDN's browser-compat-data adds two notes about where an announcement can go unheard:
- On macOS, an announcement may not be spoken if another accessibility event fires at the same moment. VoiceOver announces the other event instead. It's a VoiceOver limit, so it affects every browser on macOS.
- On ChromeOS, Chrome has the method, but announcements are never spoken. A check like line 1 can't see that.
Why it matters: ariaNotify() is the simple path in every current browser. A small live region keeps older ones covered.
When should a component announce a change?
A screen reader already reads a lot by itself. It reads the element that gets focus. And browsers must tell it when a state changes, like a switch's checked. Core-AAM requires that. So the real question is: what would Leela miss?
The ARIA Notify explainer describes how screen reader users work. When the result of an action is clear, they assume it worked. They need a message when it fails, when it's slow, or when nothing about focus or state changes. Announce these:
- The result of an action that focus doesn't show. Leela presses Add 2. Focus stays on the button, and the button doesn't change. Say: Added 2 cups of Sencha to your order.
- A count after a search or a filter. She types into the tea filter, and the list below it changes. Focus stays in the box. A short count, like 2 teas match, tells her what happened.
- An error. She asks for a 7th cup. Say why it didn't work, at once.
And skip these:
- What focus already says. Tab to a button, and the screen reader reads it.
- A state change on the element with focus. In lesson 13.2, the tea toggle sets
ariaCheckedwhen it flips. The browser reports that change. The explainer warns that extra messages for things screen readers handle lead to "confusing double-announcements". - The page loading. Leela can read the page herself. And the APG's alert pattern says screen readers don't announce alerts that are on the page before it finishes loading.
The alert pattern adds two more rules for alerts. An alert must not move focus. And it shouldn't vanish on its own before people can read it.
When Leela orders at the counter, Meena doesn't say "You're holding the menu." Leela knows. When the tea goes on the bill, which Leela can't see, Meena says "Two Sencha, on your bill." And if the Sencha runs out, Meena tells her straight away.
- In real life: "You're holding the menu"
- In HTML: Announcing what focus already says
- In real life: "Two Sencha, on your bill"
- In HTML: The result of Add, which focus doesn't show
- In real life: "Sorry, the Sencha has run out"
- In HTML: An error, with high priority
Try the rule on seven moments from Leela's visit:
- Leela presses Add 2 on the Sencha card. Focus stays on the button.
- She types
oointo the tea filter, and two teas are left in the list. - She asks for a 7th cup, and an order allows 6.
- She presses Space on the focused Add milk switch, and it turns on.
- She presses Tab and lands on the Add 1 Oolong button.
- The menu has just loaded, with four teas on it.
- She presses +, and the quantity's number, an
<output>, changes to 2.
Sort each moment: announce it, announce it at once, or don't announce it.
Why it matters: an announcement fills a gap. If nothing is missing, it only gets in the way.
How do you avoid announcing too much?
Every message costs attention. Heydon Pickering points out that you can look away from a message on screen. You can't stop hearing one. Three habits keep announcements few and useful.
Wait for a pause
Leela presses Add 1 three times, quickly. She wants 3 cups. Try two buttons:
<script src="log-announcements.js"></script><tea-add></tea-add><script src="tea-add.js"></script>ariaNotify (normal): Added 1 cup of Sencha to your order
ariaNotify (normal): Added 1 cup of Sencha to your order
ariaNotify (normal): Added 1 cup of Sencha to your orderLine 8 of the tab calls ariaNotify() on every click. Three quick clicks send three messages, each about one cup. None says the total.
- With Every click, line 8 of the
tea-add.jstab callsariaNotify()on each click. - With After a pause, line 7 counts the cups, and line 8 holds a timer.
- Each click adds a cup, on line 10. Line 11 cancels the message the last click planned. Line 12 plans a new one, 500 ms from now, as line 15 says.
- When 500 ms pass with no click, line 13 announces the total. Line 14 starts the count again.
Every click prints three lines, each about one cup. After a pause prints one: ariaNotify (normal): Added 3 cups of Sencha to your order. Waiting for a pause like this is called debouncing.
MDN explains why one is better. Some screen readers read several messages in order, but that isn't certain. "Normally, only the most recent announcement is spoken," MDN says. So combine them into one. Live regions have the same problem. The web performance course counted the events Chrome sent for a filter box: one per key, until it waited for a pause.
Meena makes Leela's three cups. She doesn't call out each time she moves a cup. She waits until the order is ready. Then she calls once, over the speaker: "Three Sencha for Leela."
- In real life: Moving each cup
- In HTML: Each click on Add 1
- In real life: Waiting until the order is ready
- In HTML: The 500 ms timer, restarted on each click
- In real life: "Three Sencha for Leela"
- In HTML: Added 3 cups of Sencha to your order
- In real life: Calling once
- In HTML: One
ariaNotify()call
Use high priority only for errors
The WAI-ARIA spec says authors should not use assertive "unless the interruption is imperative". High priority is the same idea. It cuts into whatever Leela is hearing. Use normal for results. Use high for errors she must act on now, like the 6-cup limit.
Don't say it twice
Before you announce, check what already speaks. The quantity's <output> reads its own new number. So the card must not announce the number too. It announces what nothing else says: what went into the order. And when a component announces, the page using it shouldn't say the same thing again. Exercise 6 has a page that does.
Why it matters: fewer, clearer messages are the ones people hear. Say what happened, once, at the right moment.
Announcing the tea card's Add button
Back to Leela and the Sencha card. The kit's tea-card gets everything from this lesson. These are its new lines in tea-kit/tea-card.js:
const canNotify = "ariaNotify" in Element.prototype;
.said { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
<span id="said" class="said"></span>
if (!canNotify) this.shadowRoot.getElementById("said").setAttribute("role", "status");
this.#added += this.#quantity;
clearTimeout(this.#timer);
this.#timer = setTimeout(() => this.#announce(), 500);
#announce() {
const cups = this.#added;
this.#added = 0;
const message = `Added ${cups} ${cups === 1 ? "cup" : "cups"} of ${this.#tea()} to your order`;
if (canNotify) this.shadowRoot.getElementById("add").ariaNotify(message);
else this.shadowRoot.getElementById("said").textContent = message;
}- Line 1 checks for
ariaNotify()once, when the file loads. It's line 4 of the file. - Line 3 hides the fallback region from sight, but not from the tree: 1 px, clipped.
display: nonewould leave it out of the tree. It's line 24. - Line 5 is that region, empty, at the end of the card. It's line 60.
- Line 7 gives it
role="status"only whereariaNotify()is missing. It's line 121, in the constructor, long before any press. - Lines 9 to 11 run on each press of Add. They add the quantity to a count,
#added, and restart a 500 ms timer,#timer. Both are new private fields. They're lines 128 to 130. - Lines 13 to 19 run when the timer ends. They build the message from the count and the card's tea, and reset the count. Line 17 calls
ariaNotify()on the Add button. Line 18 writes into the region instead. They're lines 142 to 148.
Here is the card on a page, with the helper:
<link rel="stylesheet" href="tea-kit/tokens.css"><script src="log-announcements.js"></script><tea-card name="Sencha" price="6"></tea-card><script type="module" src="tea-kit/index.js"></script>Line 2 loads log-announcements.js, and line 3 is a Sencha card. Press + once, then Add 2. After a short pause, the console prints ariaNotify (normal): Added 2 cups of Sencha to your order. Now press Add 2 three times, quickly. It prints one line: ariaNotify (normal): Added 6 cups of Sencha to your order. Nothing was printed when the page loaded.
Where a browser has no ariaNotify(), the card's tree gets a status region. Only the region changes:
Before Add:
status, live: polite, atomic: true, relevant: additions text
After Add:
status, live: polite, atomic: true, relevant: additions text
StaticText "Added 1 cup of Sencha to your order"Where the browser has the method, the span has no role and no words. So the card's tree is the same as with lesson 13.4's kit. The tea-add event still fires on each press, so a page can still update its own cart. The JSDoc and custom-elements.json say the card announces. This version of the kit is kitAfter135.
Common mix-ups
- "You need a hidden live region inside every component." No.
ariaNotify()works in every current major browser. Keep a live region as the fallback. - "Shadow DOM hides live regions from screen readers." No. Chrome builds the tree from the flat tree, live properties and all.
- "A live region added with its message gets read." No. The region has to exist before its text changes. An alert is the exception.
- "A region hidden with
display: nonestill speaks." No. Hidden elements are left out of the tree. Hide it from sight only, with a clip. - "High priority makes sure it's heard." No. It interrupts. Save it for errors.
- "More announcements help more." No. Often only the latest is spoken. Wait for a pause, and combine.
- "
ariaNotify()tells you whether a screen reader spoke." No. It returnsundefined, on purpose. - "A focused switch should announce its new state." No. The browser reports the change already.
Read each row across: what you write, when it's read, what is read, and what it's for.
| What you write | When it's read | What is read | Use it for |
|---|---|---|---|
role="status", or an <output>. | At the next pause. | The whole region, as it's atomic. | Results, like Added 2 cups of Sencha. |
role="alert". | At once, cutting in. | The whole region, as it's atomic. | Errors that need attention now. |
aria-live="polite". | At the next pause. | Only the changed part, unless you add aria-atomic="true". | Any element that should speak its changes. |
aria-live="assertive". | At once, cutting in. | Only the changed part, unless you add aria-atomic="true". | Rare, urgent changes. |
ariaNotify(message). | After what is being read now. | Exactly the message. | Results with no visible text to change. |
ariaNotify(message, { priority: "high" }). | At once, ahead of normal messages. | Exactly the message. | Errors that need attention now. |
Practice exercises
Answer first, then use the hints. The pages run live. To check a region's live properties, open DevTools on the result and look at the Accessibility tab.
This order history has role="log", in a shadow root. Is it atomic in Chrome's tree?
<tea-history></tea-history><script> customElements.define("tea-history", class extends HTMLElement { constructor() { super(); this.attachShadow({ mode: "open" }).innerHTML = '<div role="log"></div>'; } });</script>false. Chrome shows log, live: polite, atomic: false. A log is polite, and it reads only what's new, so old lines aren't read again.
This button waits for a pause, but each click adds 2 cups. You click Add 2 three times, quickly. What does the console print?
<script src="log-announcements.js"></script><tea-add></tea-add><script src="tea-add.js"></script>ariaNotify (normal): Added 6 cups of Sencha to your order. Each click adds 2, and restarts the wait. One message comes after the pause, with the total.
This region is made together with its words, so a screen reader may say nothing. Fix the tea-add.js tab. What role does the empty region have in Chrome's tree before any click?
<tea-add></tea-add><script src="tea-add.js"></script><tea-add></tea-add><script src="tea-add.js"></script>status. The tea-add.js tab now puts an empty <span role="status"> in the shadow root on line 5, and the click only changes its text, on line 8. Before any click, Chrome's tree has status, live: polite, atomic: true. The page stays the same.
Line 1 of this page removes ariaNotify(), like an older browser. Click Add 2, and the page throws. Fix the tea-add.js tab. What does the region say after a click?
<script>delete Element.prototype.ariaNotify; delete Document.prototype.ariaNotify;</script><tea-add></tea-add><script src="tea-add.js"></script><script>delete Element.prototype.ariaNotify; delete Document.prototype.ariaNotify;</script><tea-add></tea-add><script src="tea-add.js"></script>Added 2 cups of Sencha to your order. The tea-add.js tab is now the fallback version: line 1 checks for the method, line 10 makes the span a status as the element is made, and line 14 writes the words into it. The page stays the same.
This counter shows its number in a plain span, so a screen reader hears nothing when it changes. Make it say the final number once the clicks stop, like 3 cups. Then click + twice, quickly. What does the console print?
<script src="log-announcements.js"></script><tea-cups></tea-cups><script src="tea-cups.js"></script><script src="log-announcements.js"></script><tea-cups></tea-cups><script src="tea-cups.js"></script>ariaNotify (normal): 3 cups. In the tea-cups.js tab, change() now clears the timer and plans a call 500 ms later, on the + button. Two quick clicks make one call, with the final number. The page stays the same.
This page uses the kit's card, and also announces each tea-add event itself. Fix the page. After your fix, how many lines does one press of Add print?
<link rel="stylesheet" href="tea-kit/tokens.css"><script src="log-announcements.js"></script><tea-card name="Sencha" price="6"></tea-card><script type="module" src="tea-kit/index.js"></script><script> document.addEventListener("tea-add", (event) => { document.ariaNotify(`${event.tea}: ${event.quantity} added`); });</script><link rel="stylesheet" href="tea-kit/tokens.css"><script src="log-announcements.js"></script><tea-card name="Sencha" price="6"></tea-card><script type="module" src="tea-kit/index.js"></script>1. The page no longer listens for tea-add and calls document.ariaNotify(). The card says Added 1 cup of Sencha to your order by itself, once.
Check your understanding
For each question, ask: is there a change to read, and does anything already say it?
Question 1 of 8What live value does Chrome give the paragraph inside this shadow root?
Read the code, then predict<tea-note></tea-note> <script> customElements.define("tea-note", class extends HTMLElement { constructor() { super(); this.attachShadow({ mode: "open" }).innerHTML = '<p role="status"></p>'; } }); </script>Choose an answer to see the explanation.
Question 2 of 8A click makes a new
<span role="status">with the words already in it, and adds it to the shadow root. Why might a screen reader say nothing?Choose an answer to see the explanation.
Question 3 of 8What does
button.ariaNotify("Only 6 cups per order", { priority: "high" })ask for?Choose an answer to see the explanation.
Question 4 of 8What does
document.ariaNotify("Your order is saved")return?Choose an answer to see the explanation.
Question 5 of 8A reader clicks this button three times, quickly. How many times is
ariaNotify()called?Read the code, then predictlet cups = 0; let timer; button.addEventListener("click", () => { cups += 1; clearTimeout(timer); timer = setTimeout(() => { button.ariaNotify(`Added ${cups} cups`); cups = 0; }, 500); });Choose an answer to see the explanation.
Question 6 of 8Focus is on a switch, and Space turns it on. Should the switch also call
ariaNotify("Milk on")?Choose an answer to see the explanation.
Question 7 of 8Which check decides between
ariaNotify()and a live region?Choose an answer to see the explanation.
Question 8 of 8The kit's quantity shows its number in an
<output>. What does Chrome's tree say about it?Choose an answer to see the explanation.
Key takeaways
- A live region is read out when its text changes, wherever focus is. It works inside a shadow root.
role="status"is polite and atomic.role="alert"is assertive.aria-liveandaria-atomicset the same things by hand.- Make the region before its text changes: in the template, or in the constructor.
- An
<output>is a status already, so the kit's quantity reads its own number. ariaNotify(message, { priority })sends words with no element. Check for it with"ariaNotify" in Element.prototype, and fall back to a live region.- Announce what focus doesn't show: results, counts, and errors. Skip focus moves, focused state changes, and page loads.
- Wait for a pause, keep high priority for errors, and say each thing once.
Remember the one-liner.
Say what happened, once, without moving focus.
Sources
The facts on this page come from these standards, docs, and posts. Browser versions come from MDN's browser-compat-data:
- ARIA live regions, MDN.
- WAI-ARIA: aria-live, W3C.
- WAI-ARIA: the status role, W3C.
- WAI-ARIA: the alert role, W3C.
- Can I access a live region in light DOM from shadow DOM?, Manuel Matuzović.
- Notifications, Heydon Pickering, Inclusive Components.
- HTML-AAM: output, W3C.
- <output>: accessibility, MDN.
- Element: ariaNotify() method, MDN.
- Document: ariaNotify() method, MDN.
- WAI-ARIA: Interface Mixin ARIANotifyMixin, W3C.
- Add ariaNotify, w3c/aria pull request 2577, W3C ARIA Working Group.
- Core-AAM: ariaNotify, W3C.
- ARIA Notify explainer, Microsoft Edge.
- WAI-ARIA: excluding elements from the accessibility tree, W3C.
- ariaNotify(), web-features, on webstatus.dev.
- Alert pattern, W3C WAI, ARIA Authoring Practices Guide.
- Understanding Success Criterion 4.1.3: Status Messages, W3C WAI.
- Core-AAM: state and property change events, W3C.
- browser-compat-data, MDN.
Coming next: Focus delegation and focus styles, the first lesson of module 14, in Accessible components. It makes a host act like one control, and shows focus clearly.