Web components in today's browsers
Web components browser support, part by part: what works in every browser, what's new since 2023, the removed APIs old tutorials use, and what needs care.
- 01Read the support for each partTell which parts of web components are Baseline, and check any part in your own browser with one line of code.
- 02Know what's new and what's goneName what arrived from 2023 to 2026, and what to write today in place of each removed name.
- 03Use the newest parts with careSpot the parts that work in only some browsers, and date a tutorial by the names it uses.
Do web components work in every browser?
Ravi looks after the website of Leaf and Kettle, a small tea shop. He wants a label for each tea, like the tea label you made in the last lesson. He finds a tutorial on custom elements, copies its code, and runs it. The browser stops with an error. Is his browser too old? Do web components work at all?
Yes, they do. Custom elements, shadow DOM, templates, and slots work in every major browser, and have since January 2020. The problem was the tutorial. It used a name that browsers removed years ago.
Here is the code Ravi copied. Press Edit & run to see the error for yourself:
const proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function () {
this.textContent = "Green tea: brew for 3 minutes";
};
document.registerElement("tea-label", { prototype: proto });- Line 1 makes an object that starts with everything an HTML element has.
- Lines 2 to 4 give it a method called
createdCallback. It sets the label's text. - Line 5 tries to register the tag with
document.registerElement().
The browser stops at line 5: TypeError: document.registerElement is not a function. This code comes from an early draft of web components. Only Chrome ever had it, and Chrome removed it in Chrome 80, in February 2020.
Here is the same label, written the way every browser understands it today:
<tea-label>Green tea</tea-label> <script> class TeaLabel extends HTMLElement { connectedCallback() { this.textContent = "Green tea: brew for 3 minutes"; } } customElements.define("tea-label", TeaLabel);</script>- Line 1 puts the tag on the page, with
Green teainside. - Line 4 makes a class that extends
HTMLElement. - Lines 5 to 7 are
connectedCallback(). The browser calls it when the tag joins the page, and it sets the text. - Line 9 registers the tag with
customElements.define().
The result shows Green tea: brew for 3 minutes. Chrome, Edge, Firefox, and Safari all show the same.
You find an old map of your town in a drawer. It shows a bridge over the river. You walk there, and the bridge is gone. It was taken down years ago, and a new one stands a little way along. The map wasn't wrong. It was just old.
- In real life: The old map
- In JavaScript: An old tutorial
- In real life: The bridge that was taken down
- In JavaScript: A removed name, like
document.registerElement() - In real life: Reaching the river with no bridge
- In JavaScript:
TypeError: document.registerElement is not a function - In real life: The new bridge a little way along
- In JavaScript: Today's name,
customElements.define()
So the real question has two parts. Which parts work where? And which names are current? This picture puts every part in this lesson on one of three shelves:
- Works in every browser: the core parts, and newer ones that arrived from 2023 to 2026.
- Works in some browsers: four newer parts. You can use them, with a plan for the browsers that lack them.
- Removed: names from early drafts. Old tutorials still use them.
Web components work in every major browser. Custom elements, shadow DOM, templates, and slots have worked everywhere since January 2020, and newer parts keep arriving. When old code fails, look at its names. Some were removed, and today's browsers use new ones.
Web components browser support, part by part
"It works in every browser" is a little vague. Which browsers? From which version? Web developers use one shared label for this. It's called Baseline.
What Baseline means
Baseline is a label for web features. The WebDX Community Group decides it. That group is part of the W3C, one of the groups that write web standards. Baseline looks at the core browsers: Chrome, Edge, Firefox, and Safari, on computers and on phones. Each feature gets one of three labels:
- Limited availability: at least one core browser doesn't have it yet.
- Newly available: the newest version of every core browser has it.
- Widely available: it has been newly available for 30 months. Most sites can now use it without worry.
Your bank sends you a new kind of card. At first, only some shops can read it. Then one day, every big chain has the new reader. But a few of their counters still have old ones. A few years later, nearly every counter has been changed. Now you can pay with the card almost anywhere.
- In real life: Only some shops can read the card
- In JavaScript: Limited availability: some browsers don't have it
- In real life: Every big chain has the new reader
- In JavaScript: Newly available: the newest version of every core browser has it
- In real life: Some counters still have old readers
- In JavaScript: People still use older browser versions
- In real life: A few years on, nearly every counter has the new reader
- In JavaScript: Widely available: 30 months later
Here is how one part moved through the three labels. It's declarative shadow DOM, which you'll meet in the next section:
Chrome and Safari shipped it in March 2023. Firefox shipped it in February 2024, so it became newly available. Thirty months later, in August 2026, it became widely available. For a widely available part, you can usually skip any backup plan. For a newer part, think about who visits your site first.
Browser support for every part
Here is every part this lesson covers. Each number is the first version of that browser with the part. "No." means no version has it yet. The numbers come from MDN's browser compatibility data, and the labels from Baseline.
| Part | Chrome and Edge | Firefox | Safari | Baseline |
|---|---|---|---|---|
Custom elements, customElements.define() | 54 | 63 | 10.1 | Widely available since July 2022. |
Shadow DOM, attachShadow() | 53 | 63 | 10 | Widely available since July 2022. |
Declarative shadow DOM, shadowrootmode | 111 | 123 | 16.4 | Widely available since August 2026. |
Form-associated custom elements, setFormValue() | 77 | 98 | 16.4 | Widely available since September 2025. |
Constructable style sheets, new CSSStyleSheet() | 73 | 101 | 16.4 | Widely available since September 2025. |
Custom states, :state() | 125 | 126 | 17.4 | Widely available since November 2026. |
Turning an element back into HTML, getHTML() | 125 | 128 | 18 | Newly available since September 2024. |
Scoped registries, new CustomElementRegistry() | 146 | 159 | 26 | Newly available since October 2026. |
Customized built-in elements, is="" | 67 | 63 | No. | Limited availability. |
Moving without a reset, moveBefore() | 133 | 144 | No. | Limited availability. |
CSS module scripts, with { type: "css" } | 123 | 147 | No. | Limited availability. |
Reference Target, referenceTarget | 152 | Behind a setting. | Behind a setting. | Limited availability. |
Read the top rows first. Custom elements and shadow DOM have been widely available since July 2022. Declarative shadow DOM, form-associated elements, constructable style sheets, and custom states joined them later. getHTML() and scoped registries are newly available. The four rows at the bottom still say "Limited availability". A section below covers those four.
Check your own browser
A table tells you about browsers in general. Your code can also ask the browser it's running in. This is called feature detection: check that a name exists before you use it. It's like tapping your card on the reader to see if it beeps, instead of asking which bank the shop uses.
<script> const parts = { "Custom elements": "customElements" in window, "Declarative shadow DOM": "shadowRootMode" in HTMLTemplateElement.prototype, "Scoped registries": "initialize" in CustomElementRegistry.prototype, "moveBefore()": "moveBefore" in Element.prototype, "Reference Target": "referenceTarget" in ShadowRoot.prototype, }; for (const [part, works] of Object.entries(parts)) { console.log(`${part}: ${works ? "yes" : "no"}`); }</script>- Lines 2 to 8 make an object called
parts. Each line pairs a part's name with a question. - Each question uses
in, which asks if an object has a property with that name. The answer istrueorfalse. - Line 6 asks
Element.prototype. That's the object every element gets its methods from. So a method there is a method every element has. - Lines 9 to 11 go through the parts and print each one with yes or no.
In Chrome, all five lines say yes. In Safari 26 or later, two say no: moveBefore() and Reference Target. In Firefox 159 or later, only Reference Target says no. Feature detection is how a component uses a new part only where it exists.
Do you still need polyfills?
A polyfill is extra code that fakes a missing feature. Old tutorials load a set called webcomponentsjs on every page. You don't need it for custom elements, shadow DOM, templates, or slots. Every major browser has had them since January 2020. Scoped registries are the one exception: they reached the last browser in October 2026. A site that must work in older browsers can still load a polyfill for them.
What's new in web components since 2023?
At the start of 2023, the browsers still differed. Chrome had declarative shadow DOM and form-associated elements. Safari had neither, and Firefox had no declarative shadow DOM. Most of those gaps closed over the next few years. Here is what arrived, year by year:
- 2023. Safari 16.4 added declarative shadow DOM, form-associated custom elements, and constructable style sheets. Chrome 111 moved declarative shadow DOM to its standard attribute,
shadowrootmode. - 2024. Firefox 123 added declarative shadow DOM, so every browser had it. Two smaller parts reached every browser too:
:state()andgetHTML(). - 2025. Safari 26 shipped scoped custom element registries, the first browser to do so. Chrome and Firefox added
moveBefore(). - 2026. Firefox 147 added CSS module scripts. Chrome 146 and Firefox 159 shipped scoped registries, so they became Baseline in October. Chrome 152 turned on Reference Target.
A few of these names are new. Here is each one in plain words:
- Form-associated custom elements are tags that take part in a form, like an
<input>does. Stage 6 is all about them. - Constructable style sheets are style sheets made in JavaScript. Many shadow roots can share one.
:state()lets CSS style a component by a state it sets, like "sold out".getHTML()turns an element back into HTML, and can include its shadow root.
The rest of this section shows the two biggest arrivals running.
The browser makers fix it together
How did the gaps close? Every year, the browser makers run a project called Interop. Apple, Google, Microsoft, Mozilla, and others pick a list of focus areas together: features to fix that year. Web developers suggest them. Then every browser runs the same tests and fixes what fails.
A tea shop has kitchens in three towns. Each gets the same cake recipe, but each bakes it a little differently. So the head office sends one set of taste tests to all three. Every week, each kitchen checks its cakes and fixes what's off. In the end, every cake passes in every kitchen.
- In real life: The three kitchens
- In JavaScript: The three browser engines: Chrome's (which Edge uses too), Firefox's, and Safari's
- In real life: The recipe
- In JavaScript: The standard
- In real life: The shared taste tests
- In JavaScript: One set of tests that every browser runs
- In real life: The share of cakes that pass in every kitchen
- In JavaScript: The Interop score
Web components were a focus area in Interop 2023. When the year began, 60% of its tests passed in all three browsers. By the end, 96% did. In 2024 the focus was declarative shadow DOM: it went from 54% to 100%. Scoped registries are a focus area of Interop 2026, and the Interop 2026 dashboard shows their score. That's why these parts behave the same in every browser, not just exist in every browser.
A shadow root written in HTML
In the last lesson, a shadow root needed JavaScript: attachShadow(). Declarative shadow DOM lets you write it in HTML instead. That helps when a server builds the page. The shadow root arrives with the HTML, before any script runs.
<tea-card> <template shadowrootmode="open"> <p>Today's tea: <slot></slot></p> </template> Green tea</tea-card>- Line 1 opens a
<tea-card>. No class is defined for it, and there's no script at all. - Line 2 is a
<template>withshadowrootmode="open". The browser doesn't keep it as a template. It turns it into the card's shadow root. - Line 3 is what goes inside the shadow root: a paragraph with a slot.
- Line 5 is the card's own text,
Green tea. It shows up in the slot.
The result shows Today's tea: Green tea. It's the slot card from the last lesson, made with HTML alone.
Scoped custom element registries
Each page has one registry: the browser's list of tag names and their classes. You reach it through customElements, and each name can be in it only once. Watch what happens when two classes both want tea-label:
class ShopLabel extends HTMLElement {}
class BoxLabel extends HTMLElement {}
customElements.define("tea-label", ShopLabel);
customElements.define("tea-label", BoxLabel);- Lines 1 and 2 make two classes.
- Line 4 registers
tea-labelwithShopLabel. - Line 5 tries the same name again, with
BoxLabel. Chrome throws aNotSupportedError: the name "has already been used with this registry".
Chrome's release notes give the real-world case. An app can use components from more than one library, and two of them can pick the same name. A scoped registry fixes it. It's a second registry that only some parts of the page use. Think of two stalls in one market that both sell a "house blend". Each makes it from its own recipe book.
<tea-label></tea-label><div id="box"></div> <script> class ShopLabel extends HTMLElement { connectedCallback() { this.textContent = "Shop label"; } } class BoxLabel extends HTMLElement { connectedCallback() { this.textContent = "Box label"; } } customElements.define("tea-label", ShopLabel); const boxTags = new CustomElementRegistry(); boxTags.define("tea-label", BoxLabel); const box = document.querySelector("#box"); const shadow = box.attachShadow({ mode: "open", customElementRegistry: boxTags }); shadow.innerHTML = "<tea-label></tea-label>";</script>- Lines 5 to 10 are the two classes again. Each one sets its own text.
- Line 11 registers
ShopLabelin the page's registry, as usual. - Line 13 makes a new, empty registry with
new CustomElementRegistry(). - Line 14 registers
BoxLabelin it, under the same name. - Lines 15 and 16 find the box and give it a shadow root. The
customElementRegistryoption tells that shadow root to use the new registry. - Line 17 puts a
<tea-label>inside that shadow root.
The result shows Shop label and Box label. Inside the box, the browser looks the name up in boxTags. Everywhere else, it uses customElements.
tea-label is built from ShopLabel. Inside the box's shadow root, the same name is built from BoxLabel, because that shadow root uses its own registry, boxTags.Safari shipped scoped registries first, in Safari 26. Firefox 159 was last, in October 2026, and that made them Baseline.
What happened to HTML Imports, v0, and /deep/?
The first versions of web components were drafts. Chrome shipped them, and what developers learned from them shaped the standards. Firefox and Safari never built them. Those drafts are called v0. The versions every browser has today are called v1. The v0 drafts had three parts:
- Custom elements v0:
document.registerElement(), withcreatedCallback,attachedCallback, anddetachedCallback. - Shadow DOM v0:
createShadowRoot(), and<content>where today you write<slot>. - HTML Imports:
<link rel="import">, which loaded a whole HTML file of components.
Chrome removed all three in Chrome 80, in February 2020. Ask your own browser:
console.log("registerElement" in document);
console.log("createShadowRoot" in Element.prototype);
console.log("import" in document.createElement("link"));- Line 1 asks if
documenthasregisterElement. - Line 2 asks if elements have
createShadowRoot. - Line 3 asks if a
<link>element hasimport, the property HTML Imports added.
All three print false, in every browser. In place of HTML Imports, components now ship as JavaScript files, loaded with <script type="module">. See why JavaScript has modules for how those work.
/deep/ and ::shadow
Shadow DOM v0 also had two CSS selectors, /deep/ and ::shadow. They let the page style anything inside any shadow root. The CSS Working Group dropped /deep/: it showed too much of a component's inside to the page. Chrome made it do nothing in Chrome 63, in 2017. ::shadow went with the rest of v0.
Today, a component chooses what the page may style. It names parts of its inside with part="", and the page styles them with ::part(). Stage 4 covers styling in full.
Old names fail without an error
Here's the trap. registerElement() throws an error, so you notice. But an old CSS selector or HTML attribute fails quietly. The browser skips what it doesn't know, and the page just looks wrong. Try each button:
<style> tea-card /deep/ p { color: red; }</style> <tea-card></tea-card> <script> class TeaCard extends HTMLElement { constructor() { super(); this.attachShadow({ mode: "open" }).innerHTML = '<p>Green tea</p>'; } } customElements.define("tea-card", TeaCard); console.log(document.styleSheets[0].cssRules.length);</script>Line 2 uses /deep/. The browser doesn't understand it, so it throws the whole rule away without a word. Green tea stays its normal color, and line 15 prints 0: the style sheet has no rules left.
With /deep/, the browser throws the whole rule away, and line 15 prints 0. With ::part(), the rule stays, and Green tea turns red. With the old shadowroot, you see only the words Green tea. With shadowrootmode, the card is built. So "no errors" doesn't mean "up to date". Read the names too.
Old name, today's name
Read each row across: the name an old tutorial uses, what to write today, and when the old name went.
| Old name | Today | When it went |
|---|---|---|
document.registerElement() | customElements.define() | Custom elements v0, removed in Chrome 80. |
createdCallback, attachedCallback, detachedCallback | constructor(), connectedCallback(), disconnectedCallback() | Custom elements v0, removed in Chrome 80. |
createShadowRoot() | attachShadow({ mode: "open" }) | Shadow DOM v0, removed in Chrome 80. |
<content> | <slot> | Shadow DOM v0, removed in Chrome 80. |
<link rel="import"> | <script type="module"> | HTML Imports, removed in Chrome 80. |
/deep/ and ::shadow | ::part() or CSS custom properties | Gone with shadow DOM v0. |
shadowroot="open" | shadowrootmode="open" | Removed in Chrome 119, in 2023. |
getInnerHTML() | getHTML() | Removed in Chrome 129, in 2024. |
:--name | :state(name) | Replaced in Chrome 125, in 2024. |
assert { type: "css" } | with { type: "css" } | Removed in Chrome 126, in 2024. |
Which parts don't work in every browser yet?
Four parts in the support table still have limited availability. You can use them. Just plan for the browsers that don't have them.
Customized built-in elements with the is attribute
So far, every custom tag was new, like <tea-label>. A customized built-in element is different. It's a tag HTML already has, like <button>, with your class added through the is attribute.
<button is="order-button">Order green tea</button> <script> class OrderButton extends HTMLButtonElement { connectedCallback() { this.addEventListener("click", () => { this.textContent = "Ordered!"; }); } } customElements.define("order-button", OrderButton, { extends: "button" }); console.log(document.querySelector("button") instanceof OrderButton);</script>- Line 1 is a normal
<button>, withis="order-button". - Line 4 makes a class that extends
HTMLButtonElement, notHTMLElement. So it starts with everything a button has. - Lines 6 to 8 change the text to
Ordered!when the button is clicked. - Line 11 registers it. The third argument,
{ extends: "button" }, names the built-in tag it extends. - Line 12 prints
truein Chrome. The button is now anOrderButton.
Click the button in the result. It changes to Ordered!. But Safari doesn't support this, and won't. WebKit, the engine that runs web pages in Safari, opposes customized built-ins. In September 2026 it said no again. In Safari, the button stays a plain button. It still works, but your class never runs, and line 12 prints false.
A café gives one waiter a badge that says "tea expert". Here, the badge means an extra job: the waiter also explains each tea. In the café next door, nobody reads badges. The same waiter still takes orders there, but explains nothing.
- In real life: The waiter
- In JavaScript: The built-in
<button> - In real life: The badge
- In JavaScript:
is="order-button" - In real life: The extra job
- In JavaScript: Your
OrderButtonclass - In real life: The café that reads badges
- In JavaScript: Chrome and Firefox
- In real life: The café next door
- In JavaScript: Safari: a working button, without your class
The way that works everywhere: wrap a normal button in your own tag, like <order-button><button>…</button></order-button>. Exercise 6 asks you to build it.
Reference Target for labels inside shadow DOM
In HTML, <label for="note"> points at the element with id="note". Click the label, and the cursor goes there. But an ID can't point into a shadow root. So a label can point at your tag, but not at the input inside it.
Reference Target fixes this. The shadow root names one element inside as its reference target. Whatever points at the tag by ID is passed on to that element. It's like a front desk that passes your note to the right person.
<label for="note">Order note</label><tea-note id="note"></tea-note> <script> class TeaNote extends HTMLElement { constructor() { super(); const shadow = this.attachShadow({ mode: "open", referenceTarget: "box" }); shadow.innerHTML = '<input id="box">'; } } customElements.define("tea-note", TeaNote);</script>- Line 1 is a label for
note. Line 2 is a<tea-note>withid="note". - Line 8 attaches a shadow root with
referenceTarget: "box". - Line 9 puts an input with
id="box"inside it.
Click Order note in the result. In Chrome, the cursor jumps into the input. In browsers without Reference Target, nothing happens.
<tea-note>. Its shadow root names box as its reference target, so the browser passes the label on to the input inside.Reference Target is on by default only in Chrome, from Chrome 152. Firefox and Safari have it behind a setting, and its text is still waiting to join the HTML standard. Stage 5 shows what it means for screen readers.
CSS module scripts
A CSS module script loads a CSS file into JavaScript as a ready-made style sheet. A component can share it with its shadow root. This code needs a server that sends tea.css, so it isn't run here:
import sheet from "./tea.css" with { type: "css" };
document.adoptedStyleSheets = [sheet];- Line 1 imports
tea.css.with { type: "css" }says "this file is CSS, not JavaScript". - Line 2 applies the sheet to the page with
adoptedStyleSheets.
It works in Chrome and Firefox, not in Safari. Older tutorials write assert where today's code says with. Chrome removed assert in Chrome 126, so that line now throws a SyntaxError.
moveBefore()
Moving an element normally takes it off the page and puts it back. That resets some things. An <iframe> inside it reloads, and focus is lost. moveBefore() moves it in one step, so nothing resets. Chrome and Firefox have it. Safari doesn't yet.
Check before you use
For these four parts, use feature detection, like the check earlier in this lesson. Then give other browsers a simpler version that still works. Now sort each piece onto its shelf, as in the picture at the top:
customElements.define()attachShadow()<template shadowrootmode>new CustomElementRegistry()<button is="order-button">referenceTargetwith { type: "css" }moveBefore()document.registerElement()<link rel="import">/deep/shadowroot="open"
Sort each piece by where it works today.
How to tell if a web components tutorial is out of date
Tutorials don't always show a date. Even a date doesn't tell you everything. A post can be right about custom elements and out of date on declarative shadow DOM. The names in the code are a better clue.
You find a family photo with no date on the back. But someone in it holds a phone with a long antenna. You can't name the year, but you know the photo is old. The things in the picture tell you.
- In real life: A photo with no date
- In JavaScript: A tutorial with no date
- In real life: A phone with a long antenna
- In JavaScript: An old name, like
createdCallbackor/deep/ - In real life: Knowing it's old without the exact year
- In JavaScript: Knowing the code was written for older browsers
- In real life: Today's phones
- In JavaScript: Today's names:
customElements.define(),<slot>,shadowrootmode
Look for these signs:
document.registerElement(),createShadowRoot(),<content>, or<link rel="import">: written for the v0 drafts, which Chrome removed in 2020./deep/or::shadowin CSS: also from v0.shadowroot=orgetInnerHTML(): from Chrome's first try at declarative shadow DOM.assertin an import, or a state written:--name: both changed in 2024.- "Safari can't do this": check the support table. Safari shipped several parts before the others.
Or let this checker read the code for you. Pick each sample, or paste code from a tutorial you found:
- Line 2:
createdCallbackToday:constructor(). Custom elements v0, removed in Chrome 80, in 2020. - Line 3:
createShadowRoot()Today:attachShadow({ mode: "open" }). Shadow DOM v0, removed in Chrome 80, in 2020. - Line 4:
<content>Today:<slot>. Shadow DOM v0, removed in Chrome 80, in 2020. - Line 6:
document.registerElement()Today:customElements.define(). Custom elements v0, removed in Chrome 80, in 2020.
This code was written for browsers before these names went away. Use today's names instead.
registerElement, /deep/, and shadowroot=. It only reads the text: nothing you paste is run.The first sample has four old names. "Today's tea card" has none: it uses with, attachShadow(), and customElements.define(). The checker knows the names in this lesson's table. A clean result is a good sign, but still glance at the date.
Common mix-ups
- "Safari is behind on web components." No. Safari shipped declarative shadow DOM almost a year before Firefox, and it shipped scoped registries first. Its real gaps are
is="", CSS module scripts,moveBefore(), and Reference Target. - "You need the webcomponentsjs polyfills." No. Custom elements, shadow DOM, templates, and slots have worked in every major browser since January 2020.
- "Web components can't be built on a server." No. Declarative shadow DOM writes a shadow root in HTML, and it has been widely available since August 2026.
- "
is=""works everywhere." No. Safari doesn't support it, and WebKit has said it won't. Wrap a normal element in your own tag instead. - "
/deep/lets the page style inside any shadow root." No. Browsers dropped it. A component names its parts withpart="", and the page styles them with::part(). - "Code that runs without errors is up to date." No. Old HTML attributes and CSS selectors fail without an error. Check the names.
Practice exercises
Answer first, then use the hints. The live results let you check yourself.
What does this line print in your browser?
console.log("createShadowRoot" in Element.prototype);false. createShadowRoot() was shadow DOM v0, which no browser has today. Use attachShadow() instead.
Which of these four parts isn't Baseline?
- Declarative shadow DOM
- Form-associated custom elements
- Scoped custom element registries
- Customized built-in elements,
is=""
Number 4, customized built-ins (is=""). Safari doesn't support them. The other three work in every core browser. Scoped registries were the last to arrive, in October 2026.
This card from an older tutorial shows only Green tea. Fix it. What does the card show then?
<tea-card> <template shadowroot="open"> <p>Today's tea: <slot></slot></p> </template> Green tea</tea-card><tea-card> <template shadowrootmode="open"> <p>Today's tea: <slot></slot></p> </template> Green tea</tea-card>shadowrootmode is the name in the HTML standard. With it, the template becomes the card's shadow root, and the card shows Today's tea: Green tea.
This label throws an error in every browser. Rewrite it with today's names. What does your page show?
<tea-label></tea-label> <script> const proto = Object.create(HTMLElement.prototype); proto.attachedCallback = function () { this.textContent = "Black tea: brew for 4 minutes"; }; document.registerElement("tea-label", { prototype: proto });</script><tea-label></tea-label> <script> class TeaLabel extends HTMLElement { connectedCallback() { this.textContent = "Black tea: brew for 4 minutes"; } } customElements.define("tea-label", TeaLabel);</script>The class takes the place of the prototype object, connectedCallback() takes the place of attachedCallback, and customElements.define() takes the place of document.registerElement().
This snippet saves a card as HTML, with its shadow root. Which old name dates it, and what do you write today instead?
const card = document.querySelector("tea-card");
const html = card.getInnerHTML({ includeShadowRoots: true });
console.log(html);const card = document.querySelector("tea-card");
const html = card.getHTML({ serializableShadowRoots: true });
console.log(html);getInnerHTML() was only ever in Chrome, which removed it in Chrome 129, in 2024. Today's getHTML() works in every browser. serializableShadowRoots: true includes the shadow roots that were made serializable.
This button only gets its extra job in Chrome and Firefox. Rewrite it without is, so it works in Safari too. Click it. What does the button say?
<button is="order-button">Order green tea</button> <script> class OrderButton extends HTMLButtonElement { connectedCallback() { this.addEventListener("click", () => { this.textContent = "Ordered!"; }); } } customElements.define("order-button", OrderButton, { extends: "button" }); console.log(document.querySelector("button") instanceof OrderButton);</script><order-button> <button>Order green tea</button></order-button> <script> class OrderButton extends HTMLElement { connectedCallback() { const button = this.querySelector("button"); button.addEventListener("click", () => { button.textContent = "Ordered!"; }); } } customElements.define("order-button", OrderButton);</script><order-button> is a new tag, so it works in every browser. The real <button> inside keeps everything a button does, and your class adds the extra job.
Check your understanding
For each question, ask: does it work in every browser, in some, or in none any more?
Question 1 of 7What does "Baseline widely available" mean?
Choose an answer to see the explanation.
Question 2 of 7What does this card from an older tutorial show in Chrome today?
Read the code, then predict<tea-card> <template shadowroot="open"> <p>Today's tea: <slot></slot></p> </template> Green tea </tea-card>Choose an answer to see the explanation.
Question 3 of 7Which part works in Chrome and Firefox, but WebKit has said it won't build for Safari?
Choose an answer to see the explanation.
Question 4 of 7An old tutorial loads a component with
<link rel="import">. What do you use today?Choose an answer to see the explanation.
Question 5 of 7In the scoped registry example, what does the
<tea-label>inside the box show?Read the code, then predict<tea-label></tea-label> <div id="box"></div> <script> class ShopLabel extends HTMLElement { connectedCallback() { this.textContent = "Shop label"; } } class BoxLabel extends HTMLElement { connectedCallback() { this.textContent = "Box label"; } } customElements.define("tea-label", ShopLabel); const boxTags = new CustomElementRegistry(); boxTags.define("tea-label", BoxLabel); const box = document.querySelector("#box"); const shadow = box.attachShadow({ mode: "open", customElementRegistry: boxTags }); shadow.innerHTML = "<tea-label></tea-label>"; </script>Choose an answer to see the explanation.
Question 6 of 7Which browser shipped scoped custom element registries first?
Choose an answer to see the explanation.
Question 7 of 7A tutorial's code runs without any error. Is it up to date?
Choose an answer to see the explanation.
Key takeaways
- Custom elements, shadow DOM, templates, and slots work in every major browser, and have since January 2020.
- Baseline says how safe a part is: newly available when every core browser has it, widely available 30 months later.
- From 2023 to 2026, declarative shadow DOM, form-associated elements,
:state(), and scoped registries reached every browser. - The v0 names and HTML Imports were only ever in Chrome, which removed them in 2020.
/deep/and::shadoware gone too. is="", Reference Target, CSS module scripts, andmoveBefore()work in only some browsers. Check before you use them.- Old JavaScript names throw errors, but old HTML and CSS names fail quietly. Date a tutorial by its names.
Remember the one-liner.
The core of web components works in every browser. Old tutorials use names that are gone, and a few new parts work in only some browsers.
Sources
The facts on this page come from these standards, data sets, and release notes:
- Baseline, web.dev.
- web-features: Baseline status data, W3C WebDX Community Group.
- browser-compat-data, MDN.
- Interop 2023: Web Components, Interop project.
- Interop 2024: Declarative Shadow DOM, Interop project.
- Interop 2026: Scoped custom element registries, Interop project.
- WebKit Features in Safari 16.4, WebKit blog.
- New in Chrome 125: CSS custom :state(), Chrome for Developers.
- WebKit Features in Safari 26.0, WebKit blog.
- Chrome 146 release notes: Scoped custom element registry, Chrome for Developers.
- Firefox 159 for developers, MDN.
- DOM Standard: ShadowRootInit, WHATWG.
- Web Components update: more time to upgrade to v1 APIs, Chrome for Developers.
- Custom Elements V0: removed in Chrome 80, Chrome Platform Status.
- CSS Shadow Module Level 1: Changes, CSS Working Group.
- The is global attribute, MDN.
- Customized built-in elements: position, WebKit standards positions.
- Chrome 152 release notes: Reference target, Chrome for Developers.
- Add reference target (pull request), WHATWG HTML.
- Import attributes: CSS modules, MDN.
Coming next: When to use web components, and when not. When a web component is the right tool, and when something else fits better.