liveBook · Manning

customElements.define

customElements.define is a browser API method that registers a custom-element name with its constructor and optional built-in-element extension options.

How 2 Manning books explain it

Vanilla Web

A browser method that registers a custom element name with its constructor and optional built-in-element extension options.

How it is used
Registers application-specific or reusable HTML tags by associating a name with a component constructor.
How deep it goes
Defines the signature, naming constraints, and creation behavior; defers customized built-in elements and detailed lifecycle treatment.
Examples
Uses a greeting tag, a Bitcoin-symbol tag created through DOM APIs, and a stateful counter button.
What you can do after
Build it from scratch: register an autonomous custom element, use it in HTML or JavaScript, and handle its not-yet-defined state.

Read how Vanilla Web explains customElements.define →

Web Component Development with Modern Libraries and Tooling

A browser API method that registers a custom element name with its JavaScript class.

How it is used
Registers JavaScript web component classes so matching HTML elements can be upgraded and rendered by the browser.
How deep it goes
Defines registration, naming constraints, duplicate errors, subclass requirements, and upgrade behavior without descending into implementation internals.
Examples
Uses hello-world elements, a name attribute, greeting markup, scoped styling, and a guarded duplicate-registration pattern.
What you can do after
Builds a vanilla web component, registers it safely, loads its script, and uses its custom element in HTML.

Read how Web Component Development with Modern Libraries and Tooling explains customElements.define →

Also covered in

What to know first

Related concepts

Questions about customElements.define

What is customElements.define?

customElements.define is a browser API method that registers a custom-element name with its constructor and optional built-in-element extension options.

Which Manning books explain customElements.define?

Vanilla Web and Web Component Development with Modern Libraries and Tooling.

What should I know before learning customElements.define?

Manning books that teach customElements.define usually introduce button first.

What is the difference between customElements.define and customElement decorator?

customElements.define is a browser API method that registers a custom-element name with its constructor and optional built-in-element extension options. A Lit decorator that registers the decorated class as a custom element with a specified tag name.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.