A vanilla web component is a custom element built directly with browser APIs, without a helper library. It can be a lightweight, dependency-free choice, and understanding it makes library code easier to evaluate or debug. section 3.0 section 1.7
A greeting element
Once its defining script has loaded, <hello-world></hello-world> displays “Hello, World!” The custom tag needs both an opening and a closing tag, even though nothing is written between them. section 3.1.1 section 3.1
class HelloWorld extends HTMLElement {
connectedCallback() { #1
this.innerHTML = "<p>Hello, World!</p>"; #2
}
}
customElements.define("hello-world", HelloWorld); #3
The complete greeting implementation shows the three essentials together: extend HTMLElement, populate the element in connectedCallback, and register its hyphenated name with customElements.define. section 3.1.1
The registered name must be lowercase and contain a hyphen; registering an existing name fails. connectedCallback runs when the element is inserted into the DOM, including after reattachment. Avoid putting context-dependent rendering in the constructor: it runs before attachment and only once. section 3.1.1 section 3.11
From greeting to form control
A <radio-group> inside a form accepts attributes for its legend, labels, values, name, and selected value. Its fuller implementation clones a template into a shadow DOM, responds to attribute changes, and uses element internals so the selected value participates in form submission. section 3.10
Direct browser APIs give you control, but you also write the update logic. Replacing the whole DOM can be costly; finding and changing individual nodes can be tedious. Sharing state across components has no built-in vanilla approach. Libraries such as Lit, Stencil, FAST, and wrec build on the same APIs and can reduce this boilerplate. section 3.11 section 3.0

