MDN Web Docs

Value

A CustomElementRegistry.

Examples

Basic usage

The most common example you'll see of this property being used is to get access to the CustomElementRegistry.define() method to define and register a new custom element.

For example:

js

let customElementRegistry = window.customElements;
customElementRegistry.define("my-custom-element", MyCustomElement);

Note that the custom element class is commonly defined directly inside the define() call, as shown:

js

customElements.define(
  "element-details",
  class extends HTMLElement {
    constructor() {
      super();
      const template = document.getElementById("element-details-template");
      const shadowRoot = this.attachShadow({ mode: "open" }).appendChild(
        document.importNode(template.content, true),
      );
    }
  },
);

See our web-components-examples repo for more usage examples.

Specifications

Specification
HTML
# dom-window-customelements

Browser compatibility

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗