Home / Learn HTML / HTML Web Components and Template
HTML Web Components and Template
Create your own HTML tags, like <my-card>, and reuse them anywhere.
Definition
Web Components are your own reusable HTML tags. They rest on three parts: custom elements (a new tag name with a dash, like my-card), shadow DOM (private markup and style) and the template and slot elements.
Theory in plain words
What it is
Web Components are your own reusable HTML tags built with custom elements, shadow DOM and templates.
Why we use it
They let you reuse widgets across projects and keep styles inside.
How it works
You define a class and register it with customElements.define. The shadow DOM hides its inside from the rest of the page.
Where it is used
- Design systems
- Reusable widgets
- Embeddable components
Quick quiz
1. A custom element name must contain
Example: my-card.
2. Shadow DOM keeps
Inside styles do not leak out.
3. <template> content is
Clone it with JavaScript.