Shadow DOM: Style & Markup Encapsulation

Write the page CSS, the shadow root template and its slotted content; see how far page CSS, ::part, variables and slots reach past the boundary. An…

Why it matters

This is the foundation of Web Components. If you build a widget (a date picker, a chat bubble, an embed) that goes on other people’s sites, their CSS will collide with yours, unless its insides sit behind a shadow root. Built-in elements like <video> and <input type="range"> work the same way: their insides live in a shadow tree.

The key idea

Selectors cannot cross, inheritance can

Common mistakes

Try it in this playground