shadow DOM
A browser feature that gives a web component its own hidden DOM tree whose styles do not leak in or out.
In more detail
Ordinary CSS rules from the page cannot reach inside a shadow tree, but CSS custom properties are inherited through it. That makes custom properties the standard way to theme web components.
Example
In the browser: Page CSS does not leak in and component CSS does not leak out. Events crossing the boundary are retargeted to the host element and need composed: true to cross at all.Related terms
- DOM — The tree of objects a browser builds from a web page, which scripts read and change to update what is on screen.
- CSS custom property — A value you name yourself in CSS, such as --color-primary: #2563eb, and use elsewhere with var(--color-primary).
- composed option — An event option that lets an event cross from inside a shadow DOM out into the regular document.
- component — A reusable, self-contained piece of interface, such as a card or a modal, with its own markup, styles and behaviour.
Taught in
- CSS Custom Properties & Dynamic Theming Architecture — Design Systems & Component Engineering
- CustomEvent Dispatching And Decoupled Component Event Buses — Frontend Architecture & Web Platform