What is Web Components
Standard for reusable UI components
Web Components is a set of web standards for creating reusable custom HTML elements with encapsulated functionality.
Core Technologies
- Custom Elements — creating custom HTML tags
- Shadow DOM — style and markup encapsulation
- HTML Templates — reusable templates
- ES Modules — modular component loading
Benefits
- Work without frameworks
- Compatible with all browsers
- Style encapsulation
- Reusable across projects
Example
class MyButton extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
}
customElements.define('my-button', MyButton);
Libraries
- Lit (Google)
- Stencil (Ionic)
- FAST (Microsoft)