Web Components are a set of browser standards for creating reusable custom HTML elements, such as <user-card>, that work without a framework. They combine Custom Elements, Shadow DOM for encapsulated markup and styles, and HTML templates.

How Web Components Works

Web Components work everywhere — any framework, any page. You define a custom HTML tag like <user-card> with its own styles and behavior encapsulated in Shadow DOM. Libraries like Lit and Stencil make building web components easier than using the raw APIs.

Key Concepts

  • Shadow DOM — An isolated DOM subtree with scoped styles that can't leak out or be affected by external CSS
  • Custom Elements — The API for defining new HTML tags with custom behavior — class MyElement extends HTMLElement

Frequently Asked Questions

What are Web Components used for?

Web Components are used for design systems and widgets that must work across many apps and frameworks, because any page can use a custom element. Salesforce's Lightning Web Components and Adobe's Spectrum Web Components are built on them, and libraries such as Lit make them easier to write.

Should I use Web Components instead of React?

For most apps, no. React's ecosystem, tooling, and developer experience are superior. Web Components shine when you need framework-agnostic components — like a design system shared across React, Vue, and vanilla JS projects.