liveBook · Manning

Shadow root

Also called shadowRoot

A shadow root is the root node of an encapsulated Shadow DOM subtree attached to a host element.

How 3 Manning books explain it

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.

Read how Web Components in Action explains shadow root →

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.

Read how Vanilla Web explains shadow root →

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

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.