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.
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.
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.
Also covered in
What to know first
- buttonA button is an interactive user-interface control that a user can activate to initiate an action or select an option.
Related concepts
- Custom Elementsproduces · A custom element is an author-defined HTML element that represents application-specific content or behavior beyond that of built-in HTML elements.
- custom element nameconfigures · A custom element name is a browser-validated HTML tag name containing at least one hyphen, distinguishing it from native element names.
- Web Componentsuses · Web Components are browser standards and APIs, including custom elements and shadow DOM, for creating reusable web interface elements with encapsulated structure, presentation, and behavior.
- customElements.getcontrasts with · customElements.get is a browser API method that returns the constructor registered for a custom element name, or undefined when none is registered.
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.

