completefrontend
Open lab My progress
THE WEB COMPONENTS FIELD GUIDE

Accessibility and shadow DOM

Learn shadow DOM accessibility: how screen readers read a shadow root, why a native button inside keeps its role, where ARIA goes, and the mistakes to avoid.

By the end, you can
  • 01
    Read a component as a screen reader gets itFind its roles and names in Chrome's accessibility tree, where shadow content is read, slotted content sits at its slot, and a host with no role has no row.
  • 02
    Build on native elementsPut real buttons, links, and inputs in the shadow root, so they bring their roles, names, focus, and keys with them.
  • 03
    Give each control one ownerDecide whether the host or an element inside holds the role and the name, and avoid div buttons, aria-hidden on the host, overwritten roles, and copied labels.

Can screen readers read shadow DOM?

Leaf and Kettle's menu is made of the kit's tea cards. Leela, one of the shop's regulars, is blind. She orders on her laptop with a screen reader. It reads the page aloud. It also lets her jump from heading to heading, and from button to button.

Ravi has a worry. In lesson 6.3, the page's CSS and its querySelector() stopped at a shadow root. Every card keeps its name, its price, and its Add button in one. Can Leela's screen reader get in? And what will it say each part is?

Yes, it gets in. Screen readers read the accessibility tree, and Chrome builds that tree from the flat tree: each shadow tree in its host's place, with slotted content in its slots. So shadow content is read like any other. What counts is what each element is. A real <button> inside is a button, and a host with no role adds nothing.

Here is a small card to check:

A card that keeps its heading, price, and button in a shadow rootPop out in the code editor (opens in a new tab)HTML
<tea-card>  <span slot="name">Green tea</span></tea-card><script src="tea-card.js"></script>
ResultLoading…
  • In the tea-card.js tab, line 4 attaches an open shadow root and fills it.
  • Line 5 is a heading with a slot for the name. Line 6 is the price. Line 7 is a real button.
  • On the page, line 2 gives the card its name, Green tea.

The accessibility tree is the browser's list of what each thing on the page is. Each row has a role: what the thing is, like a heading, a button, or a link. Most rows have a name too. It says which one: Green tea, or Add. Screen readers read this tree, not the HTML. If roles and names are new to you, Accessible React components starts there.

Every tree in this lesson is shortened the same way. It leaves out the page's own row, rows Chrome ignores, plain boxes with no name, and the text inside rows that already have a name. Here is Chrome's tree for the card:

Chrome's accessibility tree for the card (shortened)Text
heading "Green tea"
paragraph
  StaticText "Price: 4"
button "Add"

Line 1 is the heading, named Green tea. Its name comes from the span the page slotted in. Line 2 is the paragraph, and line 3 is its text. Chrome calls a piece of plain text StaticText. Line 4 is the button, named Add. All four live in the shadow root, and all four are there. Yet there is no row for <tea-card> itself. The next section shows why.

To see the tree yourself, open DevTools on the result. In the Elements panel, open the Accessibility tab and turn on Show accessibility tree. The DevTools docs say this tree holds only what is "relevant and useful" for a screen reader.

Three windows. Top left, titled light tree: a card <tea-card> and a card span Green tea. Bottom left, titled shadow tree: cards h3 with the name slot, p Price: 4, and button Add. Arrows from both go right to a window titled accessibility tree, with four rows: heading Green tea, paragraph, its text Price: 4, and button Add. Under them, a faded, crossed-out card reads tea-card, labelled no row for the host.light tree<tea-card>span "Green tea"shadow treeh3 > slot namep "Price: 4"button "Add"accessibility treeheading "Green tea"paragraphStaticText "Price: 4"button "Add"tea-cardno row for the host
Chrome builds the accessibility tree from the flat tree: the shadow tree, with the page's span in its slot. The heading's name comes from the page. The host itself gets no row.
Real-life analogyA shop window shows what's on display

Ravi dresses Leaf and Kettle's front window. The shelves and price cards come from the shop's storeroom. The tea tins come from suppliers, and Ravi sets each tin on its shelf. People outside read the window as Ravi set it out. They can't tell which things came from the storeroom, and they don't need to.

In real life: The shop's own shelves and price cards
In HTML: The card's shadow tree
In real life: A tea tin from a supplier
In HTML: An element the page slots in, like <span slot="name">
In real life: The window, as Ravi set it out
In HTML: The flat tree
In real life: People reading the window from the street
In HTML: A screen reader reading the accessibility tree
The main idea

Screen readers read the flat tree. Shadow content is read like any other. Slotted content is read where its slot is. A host with no role has no row. So build with real elements inside, and give each control one owner.

Why it matters: shadow DOM doesn't lock screen readers out. Still, in the State of HTML 2025 survey, accessibility issues came third among the pain points developers named for web components. The rest of this lesson shows what makes a component easy or hard to use with a screen reader.

How does the accessibility tree see shadow DOM?

Lesson 8.2 met three trees. The light tree is what the page wrote. The shadow tree is what the component wrote. The flat tree joins them: the shadow tree, with each slot filled by what the page gave it. The CSS Shadow spec defines it. The browser draws the flat tree, and Chrome builds the accessibility tree from it too.

You can see it in the reading order. Here the page writes the price before the name. Try both orders of the slots:

Playground: which slot comes first?
A card whose shadow tree decides where the name and the price goPop out in the code editor (opens in a new tab)HTML
<tea-card>  <span slot="price">Price: 4</span>  <span slot="name">Green tea</span></tea-card><script src="tea-card.js"></script>
ResultLoading…
Chrome's accessibility tree for this page (shortened)Text
heading "Green tea"
paragraph
  StaticText "Price: 4"
Try it yourself
The heading comes first

The page wrote the price first, but the tree starts with the heading. The name slot comes first in the shadow tree.

Only lines 5 and 6 of the tea-card.js tab change places. The page always writes the price before the name.
  • On the page, line 2 writes the price, and line 3 writes the name.
  • In the tea-card.js tab, line 5 is the heading with the name slot. Line 6 is the paragraph with the price slot. The other choice swaps these two lines.

With the name slot first, the tree starts with heading "Green tea". With the price slot first, it starts with the paragraph. The page's own order made no difference. Slotted content is read where its slot is, not where the page wrote it.

Why it matters: a component decides the reading order of what it's given. Manuel Matuzović shows a card that uses this on purpose. Its heading slot comes first, so the heading is read before the picture it introduces.

Why does the host have no row?

The overview's tree had no row for <tea-card>. Three standards explain it:

  • The HTML Standard says a custom element's default role comes from its internals. With none set, it has no role.
  • HTML-AAM is the spec for how browsers pass elements on to the computer's accessibility tools. It maps such an element to the generic role.
  • WAI-ARIA calls generic "a nameless container element that has no semantic meaning on its own". It's the role of a plain <div> or <span>.

So a plain host is a box, and nothing more. Chrome ignores it. In the DevTools protocol, the reason it gives is uninteresting. The host's content moves up, under the host's parent. A host is like a paper bag at the counter: it holds the teas, but nobody lists the bag on the receipt.

A host can still have a role. The page can write one, like role="region", and the component can set one. Then the host gets a row of its own. ARIA in HTML allows any role on a custom element. Lesson 13.2 sets a default role from inside, with ElementInternals.

Does a closed shadow root change the tree?

No. With mode: "closed", Chrome's tree for the overview's card is exactly the same. Lesson 6.2 showed that closed mode only hides the root from the page's scripts.

Do native elements work inside a shadow root?

Yes, and they bring everything with them. A native element is one the browser already knows, like <button>, <a href>, or <input>. Here are four in one shadow root:

Four native controls inside one shadow rootPop out in the code editor (opens in a new tab)HTML
<p>Today's order</p><tea-order></tea-order><script src="tea-order.js"></script>
ResultLoading…
  • In the tea-order.js tab, line 6 is a button. Line 7 is a link. Line 8 is a number box with its label. Line 9 is a checkbox with its label.
  • Line 10 listens for clicks anywhere in the shadow root. Line 12 prints the tag name of what was clicked.
  • Line 11 stops the link from leaving the page, so the result stays put.

Chrome's tree lists the four controls like this:

The four controls in Chrome's accessibility treeText
button "Add"
link "Menu"
spinbutton "Cups"
checkbox "Gift wrap"

Lines 1 to 4 are the button, the link, the number box, and the checkbox. Each one has its role and its name. A spinbutton is a number box with up and down steps. Its name, Cups, comes from its <label>, which sits in the same shadow root. The checkbox gets its name from its label too.

Do keyboard keys still work?

Try it. Click Today's order in the result, then press Tab:

  • The first Tab lands on Add. Press Enter: it prints Clicked: button. Press Space: it prints the same line again.
  • The next Tab lands on Menu. Press Enter: it prints Clicked: a.
  • Two more Tabs pass the number box and reach the checkbox. Press Space: it prints Clicked: input, and the box gets its tick.

The keys turned into clicks. That's the native elements' own work, and line 10 never asked for it. Tab moved through the shadow root in page order, as lesson 9.3 showed.

Real-life analogyA light switch from the hardware store

Ravi fits a new light switch in the back room. It comes from the hardware store with its spring, its click, and the on and off marks on its plate. Anyone can use it, with a finger or an elbow. It works the same in any room he fits it in.

In real life: The switch from the store
In HTML: A native <button>
In real life: The back room it's fitted in
In HTML: The shadow root
In real life: The spring and the click
In HTML: Focus, Enter, and Space, built in
In real life: The on and off marks on its plate
In HTML: Its role and its name in the accessibility tree

Why it matters: start from native elements, and most of the work is done for you. Chrome's guide to accessible web components says the same. Use real buttons, lists, and links inside the shadow root, and keep ARIA for the gaps.

Should ARIA go on the host or inside the shadow root?

ARIA is a set of attributes, like role and aria-label, that tell screen readers what an element is. Lesson 10.1 used it for the tabs. A component has two places to put it. One is the host, the element the page sees. The other is an element inside the shadow root.

Leaf and Kettle needs an Add to cart control. Ravi can build it three ways. Try each one:

Playground: who owns the button?
An Add to cart control on a page that prints each addPop out in the code editor (opens in a new tab)HTML
<p>Today's teas</p><tea-add>Add Green tea</tea-add><script src="tea-add.js"></script><script>  const add = document.querySelector("tea-add");  add.addEventListener("click", () => console.log("Added Green tea"));</script>
ResultLoading…
Chrome's accessibility tree for this page (shortened)Text
button "Add Green tea"
Try it yourself
One button, owned by the inner element

Click Today's teas, then press Tab: the control has one Tab stop. The host has no row. The real button inside is the only control. Enter and Space work with no key code at all.

The page stays the same. Only the tea-add.js tab changes. Enter prints Added Green tea at every stop.
  • On the page, line 2 is the control. Line 6 prints Added Green tea on every click.
  • With A button inside, line 5 of the tea-add.js tab puts a real button in the shadow root, around a slot. Line 4 turns on delegatesFocus, so focus() on the host goes to the button.
  • With The host is the button, lines 6 to 10 handle Enter and Space by hand. Lines 13 and 14 give the host a role and a tab stop, unless the page already wrote them.
  • Both is the host version, with a real button inside too.

The first two give the same tree: one button, named Add Green tea. Its name comes from the slotted text. But the second had to rebuild what a native button gives for free: the role, the tab stop, and both keys. Without lines 6 to 10, Enter and Space do nothing on the host.

Both gives a button inside a button, each named Add Green tea. Tab stops on each of them, so one action takes two stops.

Two halves. Left, labelled owned inside: a window titled tea-add holds a card <button>. An arrow goes down to one tree row, button Add Green tea, labelled one control. Right, labelled owned twice: a window titled tea-add role=button also holds a card <button>. An arrow goes down to two rows, button Add Green tea, and under it, indented, another button Add Green tea, labelled two buttons, one name.Owned insidetea-add<button>button "Add Green tea"one controlOwned twicetea-add role="button"<button>button "Add Green tea"button "Add Green tea"two buttons, one name
When the button inside owns the semantics, the tree has one button. When the host takes role="button" too, Chrome's tree has a button inside a button, both with the same name.

Which one should own the role?

Pick one owner for each control's role and name. Chrome's guide gives the rule:

  • When the host wraps a native control, the control inside owns the semantics. The host gets no ARIA, and delegatesFocus passes focus in. That's the first choice.
  • When the host itself is the control, with no native element to wrap, the host owns them. It needs a role, a tab stop, and its own keys. A custom switch is one example. That's the second choice.
  • Never both. ARIA in HTML lists an element with role="button" around a <button> as a mistake. WAI-ARIA says a button's children are presentational: browsers shouldn't expose them, or "some information may be read twice". Chrome shows the inner button anyway.

Why it matters: the first choice means the least code. Reach for the second only when no native element fits.

Real-life analogyOne person answers the phone

The shop phone rings. Ravi picks up and says, "Leaf and Kettle." At the same moment, Meena picks up the other handset and says it too. The caller hears the greeting twice and isn't sure who to talk to. So the shop agrees on one rule: one person answers.

In real life: The ringing phone
In HTML: The control a screen reader reaches
In real life: Ravi answering
In HTML: The real <button> inside
In real life: Meena answering too
In HTML: role="button" on the host as well
In real life: Hearing the greeting twice
In HTML: Two buttons with one name in the tree

Can you copy aria-label from the host to the inside?

It's tempting. The page writes aria-label on the host, and the component copies it onto its inner button:

A component that copies the host's aria-label onto its buttonPop out in the code editor (opens in a new tab)HTML
<tea-add aria-label="Add Green tea">Add</tea-add><script src="tea-add.js"></script>
ResultLoading…
  • On the page, line 1 gives the host aria-label="Add Green tea".
  • In the tea-add.js tab, lines 7 and 8 copy it onto the button.
Chrome's accessibility tree for the copied labelText
generic "Add Green tea"
  button "Add Green tea"

Now the name is on two rows. Line 1 is the host. Its aria-label made Chrome give it a row, a generic one, named Add Green tea. Line 2 is the button, with the same name. ARIA in HTML doesn't allow a name on a generic host at all. WICG issue #1073 says this pattern is already common. It also says the same name on two objects "could lead to duplicate announcements".

The fix is to keep ARIA off the host. Take the words through a plain attribute, and put the ARIA inside:

A plain label attribute on the host, and aria-label only insidePop out in the code editor (opens in a new tab)HTML
<tea-add label="Add Green tea">Add</tea-add><script src="tea-add.js"></script>
ResultLoading…

Line 1 of the page now says label="Add Green tea". Line 8 of the tab reads label instead. Chrome's tree has one row, button "Add Green tea", and the host has none again. The kit's tabs work this way: their label attribute becomes the tab list's aria-label, as lesson 10.2 showed.

What are common accessibility mistakes in web components?

Four mistakes come up often in components. Each one is quick to spot in the accessibility tree.

A div that looks like a button

A <div> can be styled like a button and given a click listener. But it isn't a button. Switch between a div and a button:

Playground: a div or a button?
A card with an Add control that prints when it's clickedPop out in the code editor (opens in a new tab)HTML
<p>Today's teas</p><tea-card>Green tea</tea-card><script src="tea-card.js"></script>
ResultLoading…
Chrome's accessibility tree for this page (shortened)Text
heading "Green tea"
StaticText "Add"
Try it yourself
Text that looks like a button

Click Today's teas, press Tab, then Enter. The tree has the word Add, but no button. Tab skips it, and Enter prints nothing. Only a mouse click works.

Only line 7 of the tea-card.js tab changes. Both controls have the same green border and print the same line when clicked.
  • In the tea-card.js tab, line 5 gives the control a green border, so both choices look like buttons.
  • Line 7 is the control. Lines 8 and 9 print Added Green tea when it's clicked.

With the div, the tree has the word Add, but no button. Tab skips it, and Enter prints nothing. Only a mouse click works. With the button, Tab reaches it, and Enter prints Added Green tea. One word changed. Why it matters: a div needs a role, a tab stop, and key code to catch up. A button has all three already.

aria-hidden on the host

aria-hidden="true" takes an element and everything inside it out of the accessibility tree, MDN says. It's meant for decoration, like a squiggle of steam. Put it on the steam, then on the whole card:

Playground: where does aria-hidden go?
A card with decorative steam, a slotted name, and an Add buttonPop out in the code editor (opens in a new tab)HTML
<tea-card>  <span slot="name">Green tea</span></tea-card><script src="tea-card.js"></script>
ResultLoading…
Chrome's accessibility tree for this page (shortened)Text
heading "Green tea"
button "Add"
Try it yourself
Only the decoration is hidden

The steam has no row, and everything else is there. That's what aria-hidden is for: a decoration a screen reader shouldn't read.

Only line 1 of the page changes. Line 5 of the tea-card.js tab always hides the steam. The tree is the one before anything has focus.
  • In the tea-card.js tab, line 5 is the steam. It has aria-hidden="true" in both choices.
  • On the page, line 1 is the only line that changes. The second choice puts it on the host.

On the steam, it does its job. The steam has no row, and the rest is there. On the host, the tree is empty. The heading, the button, and even the name the page slotted in are gone. Hiding follows the flat tree, so slotted content goes with its slot. Yet the card still looks the same.

Now press Tab. Focus still lands on Add, a button the tree just said wasn't there. Chrome notices. It stops hiding the card, and DevTools' console warns: "Blocked aria-hidden on an element because its descendant retained focus." MDN says never to put aria-hidden on an element that holds something focusable.

Two windows. Left, under the code <tea-card aria-hidden=true>, a window titled tea-card holds three faded, crossed-out cards: steam, the span Green tea, labelled from the page, and button Add. Under them: all hidden, and still drawn. An arrow goes right to a window titled accessibility tree, which says empty, labelled nothing to read.<tea-card aria-hidden="true">tea-cardsteamspan "Green tea"from the pagebutton "Add"all hidden, and still drawnaccessibility tree(empty)nothing to read
aria-hidden on the host hides its whole flat subtree: the shadow tree and the name the page slotted in. The card still looks the same.
Real-life analogyA curtain over the whole shop window

A cardboard box sits at the back of the shop window, and Ravi wants it out of sight. He could put a small cover over the box. Instead, he pulls the curtain over the whole window. The box is hidden, and so are the shelves and every tea tin. The door still opens, though, and people still walk in.

In real life: The cardboard box
In HTML: The decorative steam
In real life: A small cover over the box
In HTML: aria-hidden on the steam
In real life: The curtain over the whole window
In HTML: aria-hidden on the host
In real life: The suppliers' tea tins, hidden too
In HTML: The slotted name, gone from the tree
In real life: The door that still opens
In HTML: Tab still reaching the Add button

A role that overwrites the page's role

A component may set a role on its own host. If it sets one every time, it wipes out the page's choice:

A component that always sets its host's rolePop out in the code editor (opens in a new tab)HTML
<tea-tabs role="region" aria-label="Brewing guide">  <p>Warm the pot first.</p></tea-tabs><script src="tea-tabs.js"></script><script>  console.log("Role:", document.querySelector("tea-tabs").getAttribute("role"));</script>
ResultLoading…
  • On the page, line 1 makes the element a region named Brewing guide. A region is a landmark: a part of the page that screen reader users can jump to.
  • In the tea-tabs.js tab, line 7 sets role="presentation" when the element joins the page.
  • On the page, line 6 prints the role that's left.

It prints Role: presentation. Chrome's tree shows what that did:

Chrome's accessibility tree for the overwritten roleText
generic "Brewing guide"
  paragraph
    StaticText "Warm the pot first."

The landmark is gone. Line 1 is a plain generic row, still named Brewing guide. It keeps a row because WAI-ARIA tells browsers to ignore presentation on an element with a global ARIA attribute, like aria-label. The fix is one check on line 7: if (!this.hasAttribute("role")). Then the page prints Role: region, and the tree shows region "Brewing guide". The kit's tabs have had this check since lesson 10.1.

An id reference across the boundary

aria-labelledby and aria-describedby point at other elements by id. An id reference only looks in its own tree, as lesson 6.3 showed. So a button in a shadow root with aria-labelledby="add tea" can't use a <p id="tea"> on the page. Chrome names it only Add. Alice Boxhall explains why this is hard to fix. Lesson 13.3 covers the fixes: element references and Reference Target.

Checking the tea kit's card in the accessibility tree

Time to check the kit. Here are two kit cards, as lesson 12.7 left them:

Two kit cards on a menuPop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="tea-kit/tokens.css"><tea-card><span slot="name">Green tea</span><span slot="price">Price: 4</span></tea-card><tea-card name="Oolong" price="5"></tea-card><script type="module" src="tea-kit/index.js"></script>
ResultLoading…
  • Line 2 is a Green tea card, with its name and price slotted in.
  • Line 3 is an Oolong card, with its name and price as attributes.
  • Line 4 loads the kit.
Chrome's accessibility tree for the two cards (shortened)Text
article "Green tea"
  heading "Green tea"
  paragraph
    StaticText "Price: 4"
  button "One cup less"
  status
    StaticText "1"
  button "One cup more"
  button "Add 1"
article "Oolong"
  heading "Oolong"
  paragraph
    StaticText "Price: 5"
  button "One cup less"
  status
    StaticText "1"
  button "One cup more"
  button "Add 1"

Most of it is right:

  • Lines 1 and 10 are articles, each named after its tea. The card's aria-labelledby="name" points at its own heading, in the same shadow root, so it works.
  • The quantity's buttons are named One cup less and One cup more, from their aria-label. Their text, - and +, would be a poor name on its own.
  • The number of cups is a status, the role HTML-AAM gives an <output>. Lesson 13.5 covers how changes get announced.
  • The steam isn't there at all. Its aria-hidden="true" from lesson 12.7 keeps the decoration out.

One thing is wrong. Lines 9 and 18 are two buttons with the same name, Add 1. Someone moving from button to button gets Add 1, then Add 1 again, with nothing to say which tea. It's like two order slips that both say One tea: the kitchen can't tell which table each is for. The ARIA Authoring Practices Guide asks for unique names on elements with the same role. It also puts the action word first, as in its example, Edit John Doe.

The fix uses ids in the card's own shadow root. The Add button gets two ids in aria-labelledby:

The changed line in tea-kit/tea-card.jsHTML
<button id="add" part="add" aria-labelledby="add name">Add 1</button>

Line 1 is the button from the card's template, with one new attribute. aria-labelledby takes a list of ids and joins their text in order, MDN says. It can name the element itself. So add gives Add 1, and name gives the tea. The name becomes Add 1 Green tea. The visible text stays Add 1, at the start of the name. WCAG's Label in Name asks for that, because people who use voice control say the words they see.

The same two cards with the fixed kitPop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="tea-kit/tokens.css"><tea-card><span slot="name">Green tea</span><span slot="price">Price: 4</span></tea-card><tea-card name="Oolong" price="5"></tea-card><script type="module" src="tea-kit/index.js"></script>
ResultLoading…
The two Add buttons in Chrome's tree after the fixText
button "Add 1 Green tea"
button "Add 1 Oolong"

Line 1 is the Green tea card's button, and line 2 is the Oolong card's. Now each name says its tea. Press + on the Green tea card, and its button becomes Add 2 Green tea: the name follows the text. The card's JSDoc and custom-elements.json say so on the add part. Everything else in the kit stays the same.

A quick check before the mix-ups. Is each one in Chrome's tree?

Is it in Chrome's accessibility tree?
  • An <h3> inside an open shadow root
  • An <h3> inside a closed shadow root
  • The page's <span slot="name">Green tea</span>, slotted into that <h3>
  • The <tea-card> host itself, with no role
  • The <slot> element
  • A steam <span> with aria-hidden="true"
  • The slotted name of a card whose host has aria-hidden="true"
  • A <tea-tabs> host with role="region" and aria-label="Brewing guide"
Try it yourself
0 of 8 correct

Sort each one. Nothing on these pages has focus yet.

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

Common mix-ups

  • "Shadow DOM hides content from screen readers." No. The accessibility tree comes from the flat tree. Shadow content, open or closed, is read like any other.
  • "Shadow DOM breaks accessibility." No. Roles, names, focus, and keys all work inside. What stops at the boundary is id references, like aria-labelledby. Lesson 13.3 covers those.
  • "The host is read as a custom tag." No. A host with no role has no row. Its content moves up, under the host's parent.
  • "Slotted content is read in the page's order." No. It's read where its slot is in the shadow tree.
  • "role="button" on the host makes the inner button accessible." No. It makes a button inside a button. Pick one owner.
  • "Copying aria-label inside moves it there." No. It leaves the name on both. Take a plain attribute like label instead.
  • "aria-hidden on the host hides only the shadow content." No. It hides the slotted content too, and Tab can still land inside.

Read each row across: what the component does, and who should own its role and name.

Who owns the role and the name
When the component...Who owns the role and the name?In this lesson
Wraps a native control, like a button or an input.The native element inside. The host gets no ARIA, and delegatesFocus passes focus in.tea-add with a real <button> inside.
Is the control itself, with no native element that fits.The host: a role, a tab stop, and its own keys. Lesson 13.2 sets the role with ElementInternals.tea-add with role="button" on the host.
Only arranges content the page gives it.Nobody. The host has no row, and the page's own elements keep their roles.tea-tabs, whose tabs and panels are the page's elements.
Takes a name from the page.The element inside, through a plain attribute like label. ARIA never stays on both.tea-add label="Add Green tea".

Practice exercises

Answer first, then use the hints. The pages run live. To check a tree, open DevTools on the result and turn on Show accessibility tree.

Exercise 1 · Warm-upPredict the button's name

What name does Chrome's accessibility tree give the button?

<tea-add>Green tea</tea-add><script src="tea-add.js"></script>
ResultLoading…

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

    Exercise 2 · Warm-upCount the headings

    How many headings does Chrome's accessibility tree show for this page?

    <h2>Today's teas</h2><tea-card aria-hidden="true">  <span slot="name">Oolong</span></tea-card><script src="tea-card.js"></script>
    ResultLoading…

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

      Exercise 3 · PracticeMake Remove work with the keyboard

      Click Your cart, then press Tab. Focus never reaches Remove. Fix the tea-line.js tab. Then press Tab and Enter. What does it print?

      <p>Your cart</p><tea-line>Green tea</tea-line><script src="tea-line.js"></script>
      ResultLoading…

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

        Exercise 4 · PracticeStop the doubled label

        The page prints Host: Search teas Input: Search teas. The name is on two nodes. Change the page and the tab so only the input has an aria-label. What does the page print then?

        <tea-search aria-label="Search teas"></tea-search><script src="tea-search.js"></script><script>  const search = document.querySelector("tea-search");  const input = search.shadowRoot.querySelector("input");  console.log("Host:", search.getAttribute("aria-label"), "Input:", input.getAttribute("aria-label"));</script>
        ResultLoading…

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

          Exercise 5 · ChallengeGive Buy Oolong one owner

          Click Today's teas and press Tab twice. Buy Oolong takes two stops, and Chrome's tree has a button inside a button. Change the tea-buy.js tab so the control has one owner. How many Tab stops does it have then?

          <p>Today's teas</p><tea-buy>Buy Oolong</tea-buy><script src="tea-buy.js"></script><script>  const buy = document.querySelector("tea-buy");  buy.addEventListener("click", () => console.log("Bought Oolong"));</script>
          ResultLoading…

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

            Exercise 6 · ChallengeName each Add button after its tea

            Both cards have a button named Add. Change one line of the tea-card.js tab so each name says its tea. What is the second card's button named then?

            <tea-card><span slot="name">Green tea</span></tea-card><tea-card><span slot="name">Oolong</span></tea-card><script src="tea-card.js"></script>
            ResultLoading…

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

              Check your understanding

              For each question, ask: what's in the flat tree, and which element owns the role and the name?

              The accessibility and shadow DOM quiz · 8 questionsScore: first tries count
              1. Question 1 of 8Can a screen reader read a heading that lives inside a shadow root?

                Choose an answer to see the explanation.

              2. Question 2 of 8Which row comes first in Chrome's accessibility tree for this card?

                Read the code, then predictPop out in the code editor (opens in a new tab)HTML
                <tea-card>
                  <span slot="name">Green tea</span>
                  <span slot="price">Price: 4</span>
                </tea-card>
                <script>
                  customElements.define("tea-card", class extends HTMLElement {
                    constructor() {
                      super();
                      this.attachShadow({ mode: "open" }).innerHTML =
                        '<p><slot name="price"></slot></p><h3><slot name="name"></slot></h3>';
                    }
                  });
                </script>

                Choose an answer to see the explanation.

              3. Question 3 of 8What does Chrome's accessibility tree show for a <tea-card> host that has no role?

                Choose an answer to see the explanation.

              4. Question 4 of 8A host has role="button" and its shadow root holds a real <button>. What does Chrome's tree show?

                Choose an answer to see the explanation.

              5. Question 5 of 8The page writes aria-hidden="true" on a card's host. Before anything has focus, what is left of the card in the tree?

                Choose an answer to see the explanation.

              6. Question 6 of 8A component copies its host's aria-label onto the input inside it. What goes wrong?

                Choose an answer to see the explanation.

              7. Question 7 of 8A reader clicks Today's teas, presses Tab, then Enter. What does this page print?

                Read the code, then predictPop out in the code editor (opens in a new tab)HTML
                <p>Today's teas</p>
                <tea-card></tea-card>
                <script>
                  customElements.define("tea-card", class extends HTMLElement {
                    constructor() {
                      super();
                      this.attachShadow({ mode: "open" }).innerHTML = '<div class="add">Add</div>';
                      this.shadowRoot.querySelector(".add").onclick = () => console.log("Added");
                    }
                  });
                </script>

                Choose an answer to see the explanation.

              8. Question 8 of 8When should the host itself own the role?

                Choose an answer to see the explanation.

              Key takeaways

              • Screen readers read the accessibility tree, and Chrome builds it from the flat tree. Shadow content is read, open or closed.
              • Slotted content is read where its slot is. The shadow tree decides the reading order.
              • A host with no role is generic, and Chrome gives it no row.
              • Native elements inside keep their roles, names, focus, and keys. Start from them.
              • Give each control one owner: the native element inside, or the host when the host is the control. Never both.
              • Keep ARIA off the host when the inside owns it. Take words through a plain attribute like label.
              • Don't put aria-hidden on a host, and don't overwrite the page's role. Id references stop at the boundary, and lesson 13.3 covers the fixes.

              Remember the one-liner.
              Screen readers read the flat tree, so build with real elements inside and give each control one owner.

              Sources

              The facts on this page come from these standards, docs, and posts:

              Coming next: ARIA with ElementInternals. It gives a component a default role and states, with no attributes on the host.

              CompleteFrontend Clear concepts. Working examples.