· 5 min read
Scoped custom element registries: end tag name clashes
Scoped custom element registries let web components define their own tags without global name clashes. Here's how CustomElementRegistry scoping works.

Scoped custom element registries let you register custom elements in a registry of your own instead of the single global customElements registry. You create one with new CustomElementRegistry(), define elements on it, and attach it to a shadow root, so two components can each use their own <my-button> without colliding. Since October 2026 the feature is Baseline newly available, supported in Chrome and Edge 146, Firefox 159 and Safari 26.
That fixes one of the oldest practical problems with web components: tag names were global, and only one definition per name could exist on a page.
What problem do scoped custom element registries solve?
A custom element registry is the table that maps a tag name like date-picker to the class that implements it. Until now every page had exactly one, window.customElements, and calling define() twice with the same name throws a NotSupportedError.
That is fine when one team owns the whole page. It breaks down in a few common situations:
- Two design systems on one page both ship a
ui-button. - A micro-frontend bundles version 2 of a component while the host app still uses version 1.
- A third-party widget defines a generic name like
x-iconthat your own code also wants.
The usual workarounds were renaming tags with prefixes at build time, or wrapping define() in a check and hoping the already-registered version is compatible. Neither is great. Prefixes leak into every template, and "whoever registers first wins" is a quiet source of bugs that depend on script load order.
A scoped registry turns the tag name into something local. Inside a given shadow root, ui-button means whatever that shadow root's registry says it means.
How do you create and attach a scoped registry?
There are three steps: construct a registry, define elements on it, and hand it to attachShadow() through the customElementRegistry option.
const registry = new CustomElementRegistry();
registry.define('ui-button', class extends HTMLElement {
connectedCallback() {
this.textContent = 'Scoped button';
}
});
const host = document.querySelector('#widget');
const shadow = host.attachShadow({
mode: 'open',
customElementRegistry: registry,
});
shadow.innerHTML = '<ui-button></ui-button>';
The <ui-button> inside that shadow root upgrades using the scoped definition. A <ui-button> in the main document is unaffected; it still resolves against the global registry, which might define something completely different or nothing at all.
Definitions made on a scoped registry are not visible anywhere else. They only apply to nodes associated with that registry. The constructor takes no arguments, and the instance has the same methods as the global registry: define(), get(), getName(), whenDefined() and upgrade(), plus a new one, initialize(), covered below.
Inside a component class, the natural place to do this is the constructor, with a registry created once per component module:
const registry = new CustomElementRegistry();
registry.define('ui-button', UiButton);
registry.define('ui-icon', UiIcon);
class SettingsPanel extends HTMLElement {
constructor() {
super();
const root = this.attachShadow({ mode: 'open', customElementRegistry: registry });
root.innerHTML = '<ui-button><ui-icon></ui-icon> Save</ui-button>';
}
}
customElements.define('settings-panel', SettingsPanel);
Only settings-panel touches the global registry. Its internal parts stay private.
How does it work with declarative shadow DOM?
Declarative shadow DOM is the <template shadowrootmode="open"> syntax that creates a shadow root from HTML, typically for server rendering. Since no script runs at parse time, you can't pass a registry object. Instead you add the shadowrootcustomelementregistry attribute, which marks the shadow root as one that will get a scoped registry, and then attach it from script with initialize():
<order-summary>
<template shadowrootmode="open" shadowrootcustomelementregistry>
<price-tag>42</price-tag>
</template>
</order-summary>
const registry = new CustomElementRegistry();
registry.define('price-tag', PriceTag);
registry.initialize(document.querySelector('order-summary').shadowRoot);
initialize() sets the registry on the given node and every descendant, and upgrades any matching custom elements it finds. It is also how you scope a whole detached document, for example one made with document.implementation.createHTMLDocument('') for off-screen template work.
Can you scope elements created with createElement?
Yes. document.createElement() accepts a customElementRegistry option:
const el = document.createElement('price-tag', { customElementRegistry: registry });
el.customElementRegistry === registry; // true
The element and the custom elements in its subtree resolve against that registry wherever you later insert them. Elements, shadow roots and documents all expose a read-only customElementRegistry property, so you can check which registry a node belongs to. Once a node or shadow root has a registry, it can't be swapped for another one.
| Where you set it | How |
|---|---|
| Shadow root from script | attachShadow({ mode, customElementRegistry }) |
| Declarative shadow root | shadowrootcustomelementregistry attribute, then registry.initialize(root) |
| Single element | document.createElement(name, { customElementRegistry }) |
| Detached document | registry.initialize(doc) |
What are the limits?
A few things are worth knowing before you adopt it:
- No customized built-ins. Calling
define()with theextendsoption on a scoped registry throws aNotSupportedError. Scoped registries are for autonomous custom elements like<ui-button>, not<button is="ui-button">. - Set once. You can't reassign a shadow root's registry after it's set, so decide at
attachShadow()time. - Older browsers. Baseline newly available means the latest versions of every major engine. Users on older versions won't have the constructor, so feature-detect before relying on it:
const supportsScoped = (() => {
try {
new CustomElementRegistry();
return true;
} catch {
return false;
}
})();
Before the native feature existed, the common fallback was the community scoped-registry polyfill, and some component libraries shipped their own scoping helpers. If your library uses one of those, the native API is the thing it was approximating, so it's worth checking whether it now defers to the browser.
Key takeaways
new CustomElementRegistry()creates a registry whose definitions apply only to nodes associated with it.- Pass it to
attachShadow()with thecustomElementRegistryoption to scope a component's internals. - For declarative shadow DOM, add
shadowrootcustomelementregistryand callregistry.initialize(shadowRoot). - Customized built-ins (
extends) are not supported in scoped registries. - Supported in Chrome and Edge 146, Firefox 159 and Safari 26; feature-detect for older versions.
FAQ
Do scoped registries replace window.customElements?
No. The global registry still exists and still defines elements in the main document. Scoped registries sit beside it, and a typical component registers its own public tag globally while keeping its internal parts in a scoped registry.
Can two scoped registries define the same tag name?
Yes, that's the point. Each registry has its own name table, so ui-button can map to different classes in different shadow roots on the same page.
Do I need declarative shadow DOM to use scoped registries?
No. The script-only path with attachShadow() works on its own. The shadowrootcustomelementregistry attribute only matters when the shadow root comes from server-rendered HTML.