HTML5 & Web APIs (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
HTML Web Components: Custom Elements, Shadow DOM, and Templates.
senior LevelComponentsSystem Design
In Simple Words: Web Components are a suite of browser-native technologies for creating reusable custom HTML tags:
- Custom Elements (
customElements.define): JavaScript API to define custom HTML tags (<user-avatar>). - Shadow DOM (
element.attachShadow({ mode: 'open' })): An isolated DOM subtree where CSS styles inside the shadow root do not leak out or get overridden by external styles. <template>&<slot>: Inert HTML markup cloned dynamically into shadow roots with projection placeholders.