JavaScript Document customElementRegistry Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

document.customElementRegistry is a read-only property that returns the CustomElementRegistry for this document, or null if none is set (MDN). On a normal page it is the same object as window.customElements.

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use document.customElementRegistry. Start with this line.

JavaScript
document.customElementRegistry
CallWhat it does
document.customElementRegistryPrimary signature.

Built into the browser. Read or assign document.customElementRegistry — no import required.

Library declarations
JavaScript
document.customElementRegistry

Parameters

ParameterDescription
Writable?Optional. Read-only property

Return Value

Return ValueDescription
*CustomElementRegistry or null

JavaScript Examples

Example 1 — Same as window.customElements (MDN)

On the main document, the registries match when the Document property exists.

JavaScript
if ("customElementRegistry" in document) {
  console.log(
    document.customElementRegistry === window.customElements
  ); // true on Window-associated docs (MDN)
} else {
  console.log("document.customElementRegistry not supported");
}
Try It Yourself

How It Works

  1. Detect the Document property first — Limited availability (MDN).
  2. Compare references with window.customElements.
  3. Equal on the main page when both exist (MDN).
  4. Defining custom elements still uses that shared registry.

Example 2 — createHTMLDocument Is null (MDN)

Programmatic documents start without a custom element registry.

JavaScript
const newDoc = document.implementation.createHTMLDocument("New document");

if ("customElementRegistry" in newDoc) {
  console.log(newDoc.customElementRegistry); // null (MDN default)
} else {
  console.log("(property not supported)");
}
Try It Yourself

How It Works

  1. Create a blank HTML document via implementation.createHTMLDocument.
  2. Read its registry — MDN: default is null.
  3. Unlike the main page, there is no global registry wired in automatically.
  4. Do not assume every Document has a usable registry.

Example 3 — Feature-Detect and Fallback

Prefer the Document property when present; otherwise use window.customElements.

JavaScript
const hasDocProp = "customElementRegistry" in document;
const registry = hasDocProp
  ? document.customElementRegistry
  : window.customElements;

console.log(hasDocProp);
console.log(!!registry);
Try It Yourself

How It Works

  1. Detect whether the Document property exists.
  2. Choose a registry — Document property or window.customElements.
  3. Check truthiness — still may be null on some documents.
  4. Safe for production when you need a registry without requiring the newer Document accessor.

Browser Support

Document.customElementRegistry is Limited availability on MDN (not Baseline). The related window.customElements / CustomElementRegistry APIs are much more widely available — prefer them with a fallback.

✓ Limited · Not Baseline

Document.customElementRegistry

Returns the document’s CustomElementRegistry or null. Feature-detect; fall back to window.customElements.

Ltd Limited
Google Chrome Check current — feature-detect
Check
Microsoft Edge Check current — feature-detect
Check
Mozilla Firefox May lag — feature-detect
Check
Apple Safari May lag — feature-detect
Check
Opera Follow Chromium where available
Check
Internet Explorer No
No
customElementRegistry Limited

Bottom line: Detect before use. See the MDN customElementRegistry reference.

Frequently Asked Questions

MDN: the CustomElementRegistry associated with this document, or null if one has not been set.
MDN does not mark it Deprecated, Experimental, or Non-standard. It is Limited availability (not Baseline) — feature-detect before production use.
MDN: for Window-associated documents they are the same global registry. document.customElementRegistry can be null on some programmatically created documents.
MDN: documents created programmatically (for example via DOMImplementation.createHTMLDocument()) have a null custom element registry by default.
Yes. MDN: the same customElementRegistry property is also available on ShadowRoot (useful for scoped registries).
Yes. Defining elements with customElements.define() is the everyday API. Use document.customElementRegistry when you need the document's registry object or null/scoped cases.

Next: defaultView

Continue with the Document defaultView property.

defaultView →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful