liveBook · Manning

Custom element name

As explained in Web Component Development with Modern Libraries and Tooling

A custom element name is the registered, hyphenated HTML tag name associated with a custom element definition.

A custom element name is the registered, hyphenated HTML tag name that connects a web component class with its markup. It must be lowercase and contain at least one hyphen, distinguishing it from built-in elements such as div and textarea. section 3.1

Follow these naming and registration rules:

  • Avoid uppercase letters, a leading hyphen, reserved SVG and MathML names, and names already registered. section 3.1.1
  • Register the name with customElements.define and a class extending HTMLElement; the browser then upgrades matching document elements. section 1.4 section 3.1.1
  • Write custom elements with explicit closing tags, even when they have no content. section 3.1
  • Check customElements.get before defining a name when repeated loading or library conflicts are possible. section 3.1.1

A hello-world element

class HelloWorld extends HTMLElement { connectedCallback() { this.innerHTML = "<p>Hello, World!</p>"; } } customElements.define("hello-world", HelloWorld); <hello-world></hello-world> The hyphenated name is registered globally, and the matching tag is upgraded when the browser processes the page. section 3.1.1

Figure 1.3 Step-by-step flow, from initial page request to functioning web components.
web component flow

Trace the path from page loading and script execution to custom element registration and browser upgrade. section 1.4

How Web Component Development with Modern Libraries and Tooling covers it

How deep it goes
Defines syntax, registration, upgrade behavior, duplicate checks, reserved names, and explicit closing tags.
Examples
Uses the hello-world class, registration call, matching HTML tag, and page-loading upgrade flow.
What it assumes
Assumes basic HTML, JavaScript classes, scripts, and browser page loading while explaining naming rules explicitly.
What you can do after
Build it from scratch by naming, registering, safely checking, and placing a vanilla web component.
How it connects
Connects web components with HTMLElement, customElements.define, customElements.get, the DOM, and HTML elements.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Component Development with Modern Libraries and Tooling. The section links point to the parts of the book it draws on.