Upgrading and Progressive Enhancement
You'll learn how browsers automatically upgrade unknown HTML elements into fully functional custom elements once their definitions are registered.
The Core Concept
When you use a custom element tag like <user-card> in your HTML before its class definition is registered, the browser doesn't throw an error. Instead, it creates an undefined element — basically a generic HTMLElement with the right tag name, just sitting there waiting. The moment you call customElements.define('user-card', UserCard), the browser performs an upgrade: it transforms all existing instances of that tag into proper UserCard instances, triggering their constructors and connectedCallback methods.
This means your HTML can reference custom elements immediately, even if the JavaScript defining them loads later. The elements will appear in the DOM right away (as undefined placeholders), then "come alive" once their definitions arrive.
Why This Matters
This behavior enables progressive enhancement. Your page renders immediately with semantic markup like <user-card name="Alice"></user-card>, displaying basic content or a loading state. When the JavaScript loads — whether delayed by network conditions, async loading, or code-splitting — the browser automatically upgrades these elements to their full interactive versions.
Think of it like ordering at a restaurant: your table reservation (the HTML tag) is honored immediately, but the fancy presentation and service (the custom element behavior) arrives when the kitchen (JavaScript) is ready.
Key Takeaway:
Browsers automatically upgrade undefined custom element tags to their full implementations when customElements.define() is called, enabling HTML-first progressive enhancement without manual initialization code.