Web Component
ELI5 — The Vibe Check
Web components are custom HTML elements that you build yourself — like creating your own LEGO brick. Instead of using a framework's component system, you use browser-native APIs to define reusable elements like
Real Talk
Web Components are a set of browser-native APIs (Custom Elements, Shadow DOM, HTML Templates, and ES Modules) that enable the creation of reusable, encapsulated HTML elements. They provide framework-agnostic component architecture with style isolation through Shadow DOM. While adoption has been slower than framework-based components, they excel in design systems that need to work across multiple frameworks.
Show Me The Code
class MyCounter extends HTMLElement {
constructor() {
super();
this.count = 0;
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<button id="btn">Count: 0</button>
`;
this.shadowRoot.getElementById('btn')
.addEventListener('click', () => {
this.shadowRoot.getElementById('btn')
.textContent = `Count: ${++this.count}`;
});
}
}
customElements.define('my-counter', MyCounter);
When You'll Hear This
"Use web components for the design system — it needs to work in React AND Vue." / "Shadow DOM keeps your component styles from leaking out."
Related Terms
Custom Elements
Custom Elements let you define your own HTML tags that the browser recognizes as first-class citizens. Want a <fancy-tooltip> tag?
Design System
A LEGO set for your UI — a collection of reusable components, colors, typography, and rules that keep your entire app looking consistent.
HTML (HyperText Markup Language)
HTML is like the skeleton of a webpage. You write tags like <h1> and <p> and the browser builds the bones of your site from them.
Lit
Lit is Google's way of saying 'Web Components don't have to be painful.
Shadow DOM
Shadow DOM is like a force field around your component's internals.