completefrontend
Open lab My progress
THE WEB COMPONENTS FIELD GUIDE

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.

By the end, you can
  • 01
    Announce 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.
  • 02
    Use ariaNotify() with a fallbackSend a message with ariaNotify(), pick normal or high priority, and fall back to a live region where a browser has no ariaNotify().
  • 03
    Announce 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.

A button and a status region in one shadow rootPop out in the code editor (opens in a new tab)HTML
<tea-add></tea-add><script src="tea-add.js"></script>
ResultLoading…
  • In the tea-add.js tab, line 5 puts a button and an empty span in the shadow root. The span has role="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:

Chrome's accessibility tree, before and after the clickText
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.

Two windows. Left, titled shadow root: a card <button>Add 2</button> and a card <span role="status">. An arrow labelled builds goes to the right window, titled Chrome's tree: a card button "Add 2" and a card status, live: polite. From the status card, an arrow labelled the change is read out goes down to a card: Added 2 cups of Sencha to your order.shadow root<button>Add 2</button><span role="status">buildsChrome's treebutton "Add 2"status, live: politethe change is read outAdded 2 cups of Sencha to your order
The status region sits in the shadow root, and Chrome's tree still has it, with its live properties. When its text changes, a screen reader can read the change out, wherever focus is.
Real-life analogyThe café's speaker

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
The main idea

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, from aria-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, from aria-atomic, says how much to read. true reads the whole region. false reads only the part that changed.
  • relevant, from aria-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:

Playground: which kind of live region?
tea-add, with four kinds of regionPop out in the code editor (opens in a new tab)HTML
<tea-add></tea-add><script src="tea-add.js"></script>
ResultLoading…
Chrome's accessibility tree after a click on Add 2Text
button "Add 2", focused: true
status, live: polite, atomic: true, relevant: additions text
  StaticText "Added 2 cups of Sencha to your order"
Try it yourself
A status is polite and atomic

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.js tab changes. Click Add 2 in the result each time.
  • Only line 5 of the tea-add.js tab 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:

A status region made together with its wordsPop out in the code editor (opens in a new tab)HTML
<tea-add></tea-add><script src="tea-add.js"></script>
ResultLoading…
  • In the tea-add.js tab, 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.
Chrome's accessibility tree for the late regionText
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.

Two halves. Left, Region first: at load, a card <span role="status"></span>. An arrow labelled click goes down to a card "Added 2 cups of Sencha…", labelled a change: read out. Right, Region and text together: at load, a crossed-out card no region. An arrow labelled click goes down to a card <span role="status">Added…, labelled first content: often not read.Region firstat load<span role="status"></span>click"Added 2 cups of Sencha…"a change: read outRegion and text togetherat loadno regionclick<span role="status">Added…first content: often not read
A screen reader reads changes in the regions it already knows. On the left, the click changes a region that was there all along. On the right, the region and its words arrive together, so there's no change to read.
Real-life analogyThe now-serving screen

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:

The kit's quantity, labelledPop out in the code editor (opens in a new tab)HTML
<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>
ResultLoading…

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:

Chrome's accessibility tree after one click on +Text
StaticText "Cups"
button "One cup less"
status "Cups", live: polite, atomic: true, relevant: additions text
  StaticText "2"
button "One cup more", focused: true

Line 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:

A button that calls ariaNotify() on itselfPop out in the code editor (opens in a new tab)HTML
<script src="log-announcements.js"></script><tea-add></tea-add><script src="tea-add.js"></script>
ResultLoading…
  • On the page, line 1 loads a helper, in the log-announcements.js tab. Line 2 is the tag, and line 3 loads it.
  • In the tea-add.js tab, line 5 puts only a button in the shadow root. Lines 7 to 9 call button.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:

log-announcements.js: print each announcementJavaScript
// 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 Element and Document, 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:

What ariaNotify() returnsPop out in the code editor (opens in a new tab)JavaScript
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.

Real-life analogyPicking up the microphone

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), or ariaNotify(announcement, { priority }). It returns undefined.
  • priority is 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 on document, 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 the hidden attribute.
  • A frame can use it, unless the page turns the aria-notify permissions 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:

Normal priority for news, high for an errorPop out in the code editor (opens in a new tab)HTML
<script src="log-announcements.js"></script><tea-add></tea-add><script src="tea-add.js"></script>
ResultLoading…
  • In the tea-add.js tab, line 7 counts the cups in the order.
  • Line 9 checks whether 2 more would pass 6. If so, line 10 calls ariaNotify() with priority: "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:

Playground: with and without ariaNotify()
tea-add, with a live region to fall back onPop out in the code editor (opens in a new tab)HTML
<!-- ariaNotify() as the browser has it --><script src="log-announcements.js"></script><tea-add></tea-add><script src="tea-add.js"></script>
ResultLoading…
Chrome's accessibility tree, and the consoleText
Before the click:
button "Add 2"

After the click:
button "Add 2", focused: true

Console:
ariaNotify (normal): Added 2 cups of Sencha to your order
Try it yourself
ariaNotify() is called, and the tree stays the same

Line 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.

Only line 1 of the page changes. The tea-add.js tab is the same each time.
  • In the tea-add.js tab, line 1 checks once: "ariaNotify" in Element.prototype. It's true where 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 ariaChecked when 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.

Real-life analogyA good waiter

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:

Announce it or not?
  • Leela presses Add 2 on the Sencha card. Focus stays on the button.
  • She types oo into 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.
Try it yourself
0 of 7 correct

Sort each moment: announce it, announce it at once, or don't announce it.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

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:

Playground: every click, or after a pause?
tea-add, announcing each click or the totalPop out in the code editor (opens in a new tab)HTML
<script src="log-announcements.js"></script><tea-add></tea-add><script src="tea-add.js"></script>
ResultLoading…
What the console prints after three quick clicksText
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 order
Try it yourself
Three clicks, three announcements

Line 8 of the tab calls ariaNotify() on every click. Three quick clicks send three messages, each about one cup. None says the total.

The page is the same each time. Only the tea-add.js tab changes. Click Add 1 three times, quickly.
  • With Every click, line 8 of the tea-add.js tab calls ariaNotify() 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.

A timeline. Three thin bars labelled click, close together. After the last one, a shaded bar labelled 500 ms with no click. From its end, an arrow labelled ariaNotify(), once goes down to a card: Added 3 cups of Sencha to your order.clickclickclick500 ms with no clickariaNotify(), onceAdded 3 cups of Sencha to your order
Each click starts the wait again. Only when 500 ms pass with no click does the button speak, once, with the total.

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.

Real-life analogyThe order-ready call

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:

The tea card's new linesJavaScript
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: none would 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 where ariaNotify() 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:

The kit's tea card, announcingPop out in the code editor (opens in a new tab)HTML
<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>
ResultLoading…

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:

The card's region without ariaNotify(), before and after a press of Add 1Text
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: none still 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 returns undefined, 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.

Which way to announce?
What you writeWhen it's readWhat is readUse 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.

Exercise 1 · Warm-upIs an order history atomic?

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>
ResultLoading…

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upTwo cups a click

    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>
    ResultLoading…

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeMake the region first

      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>
      ResultLoading…

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeFall back without ariaNotify()

        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>
        ResultLoading…

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeSay the final number

          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>
          ResultLoading…

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeDon't say it twice

            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>
            ResultLoading…

            Answer, then press Check. Spacing and letter case don’t matter.

              Check your understanding

              For each question, ask: is there a change to read, and does anything already say it?

              The announcing changes quiz · 8 questionsScore: first tries count
              1. Question 1 of 8What live value does Chrome give the paragraph inside this shadow root?

                Read the code, then predictPop out in the code editor (opens in a new tab)HTML
                <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.

              2. 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.

              3. Question 3 of 8What does button.ariaNotify("Only 6 cups per order", { priority: "high" }) ask for?

                Choose an answer to see the explanation.

              4. Question 4 of 8What does document.ariaNotify("Your order is saved") return?

                Choose an answer to see the explanation.

              5. Question 5 of 8A reader clicks this button three times, quickly. How many times is ariaNotify() called?

                Read the code, then predictPop out in the code editor (opens in a new tab)JavaScript
                let 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.

              6. 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.

              7. Question 7 of 8Which check decides between ariaNotify() and a live region?

                Choose an answer to see the explanation.

              8. 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-live and aria-atomic set 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:

              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.

              CompleteFrontend Clear concepts. Working examples.