Shadow root
A shadow root is the root node of an encapsulated Shadow DOM subtree attached to a host element.
Web Components in Action
A shadow root is the root node of an encapsulated Shadow DOM subtree attached to a host element, with open or closed access modes.
- How it is used
- Uses a separate DOM tree to hold custom-element internals, accept slotted content, and limit ordinary DOM and CSS access.
- How deep it goes
- Works through attachment, open and closed access, querying, and fallback initialization; cautions that closed mode does not stop malicious interference.
- Examples
- Uses a minimal custom element, a slotted business card, and a component with isolated CSS.
- What you can do after
- Build it from scratch with `attachShadow`, choose an access mode, and retain a root reference when needed.
Vanilla Web
A shadow root is the encapsulated DOM subtree attached to a shadow host for implementing a web component's internal structure and presentation.
- How it is used
- Isolates a web component’s internal DOM and styles from accidental interference by the host page.
- How deep it goes
- Explains attachment, open and closed access, rendering placement, styling, declarative creation, and testing; defers detailed slot behavior.
- Examples
- Contrasts a button styled by page CSS with an isolated component, then shows a declarative product card and slot assertions.
- What you can do after
- Build it from scratch with `attachShadow()` or declarative HTML, then render into and test the resulting tree.
Web Component Development with Modern Libraries and Tooling
The browser object representing the root of a shadow DOM tree.
- How it is used
- Encapsulates a web component’s rendered DOM and provides the component’s target for initial rendering and updates.
- How deep it goes
- Explains creation, open or closed access, internal queries, rendering methods, and template cloning, but not deeper browser internals.
- Examples
- Uses custom elements, sortable tables, template cloning, internal table queries, and DevTools inspection of shadow roots.
- What you can do after
- Build vanilla web components that attach, render, update, query, and inspect their shadow DOM.
Read how Web Component Development with Modern Libraries and Tooling explains shadow root →
Related concepts
- attachShadowproduced by · A DOM method that attaches a shadow root to an element and returns the resulting ShadowRoot object.
- DOM fragmentkind of · A DOM fragment is a lightweight, detached node that can hold a subtree of nodes independently of a document tree.
- Shadow DOMhas part · Shadow DOM is a web platform mechanism for attaching a DOM subtree to an element while encapsulating its structure and styles from the surrounding document.
- connectedcallbackused by · connectedCallback is a custom-element lifecycle callback invoked when the element is connected to a document's DOM.
- declarative shadow rootproduced by · A declarative shadow root is a shadow DOM tree specified in HTML markup and attached by the browser during parsing.
Questions about shadow root
What is shadow root?
A shadow root is the root node of an encapsulated Shadow DOM subtree attached to a host element.
Which Manning books explain shadow root?
Web Components in Action, Vanilla Web and Web Component Development with Modern Libraries and Tooling.
What is shadow root a kind of?
Shadow root is a kind of DOM fragment. A DOM fragment is a lightweight, detached node that can hold a subtree of nodes independently of a document tree.
What are the parts of shadow root?
Shadow root includes Shadow DOM.
What is shadow root also called?
Shadow root is also called shadowRoot.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


