| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/customElementRegistry | [Back] [Original] |
Get to know MDN better
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Want more browser support for this feature? Tell us why.
The customElementRegistry read-only property of the ShadowRoot interface returns the CustomElementRegistry object associated with this shadow root, or null if one has not been set.
A shadow root's customElementRegistry determines which custom element definitions are used for upgrading elements within that shadow tree. It can be set when the shadow root is created via the customElementRegistry option of Element.attachShadow(), or later using CustomElementRegistry.initialize(). Once set to a CustomElementRegistry object, it cannot be changed.
This property is also available on Document objects via the same customElementRegistry property name.
A CustomElementRegistry object, or null.
This example creates a scoped registry with a custom element definition and passes it to Element.attachShadow(). The customElementRegistry property on the resulting shadow root reflects the scoped registry.
const myRegistry = new CustomElementRegistry();
myRegistry.define(
"my-element",
class extends HTMLElement {
connectedCallback() {
this.textContent = "Hello from scoped registry!";
}
},
);
const host = document.createElement("div");
document.body.appendChild(host);
const shadow = host.attachShadow({
mode: "open",
customElementRegistry: myRegistry,
});
shadow.innerHTML = "<my-element></my-element>";
console.log(shadow.customElementRegistry === myRegistry); // true
console.log(shadow.querySelector("my-element").textContent);
// "Hello from scoped registry!"
| Specification |
|---|
| DOM # dom-documentorshadowroot-customelementregistry |
Document.customElementRegistryElement.customElementRegistryCustomElementRegistryCustomElementRegistry() constructorElement.attachShadow()This page was last modified on Feb 22, 2026 by MDN contributors.
ShadowRootYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |