liveBook · Manning

Shadow DOM

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.

How 4 Manning books explain it

Web Components in Action

Shadow DOM is a web platform mechanism that attaches an encapsulated DOM subtree to an element and isolates its internal structure and styling from the surrounding document.

How it is used
Protects custom-element internals from accidental document queries and page-level CSS collisions.
How deep it goes
Works through root creation, access modes, CSS isolation, constructor timing, and compatibility fallbacks; treats closed mode as impractical rather than secure.
Examples
Uses a date input’s hidden UI, an exposed component query, a styled stepper, and a slider conversion.
What you can do after
Build it from scratch with `attachShadow`, scope internal DOM and CSS, and choose a fallback when native support is unavailable.

Read how Web Components in Action explains Shadow DOM →

Web Component Development with Modern Libraries and Tooling

A browser platform feature that encapsulates a DOM subtree and its styling from the surrounding document.

How it is used
Encapsulates a web component’s DOM and CSS to reduce accidental styling conflicts and manipulation by page code.
How deep it goes
Explains styling, querying, event boundaries, attachment timing, and open versus closed modes; defers fuller event treatment.
Examples
Uses a styled radio-group template with named slots and a table component whose styles would otherwise affect the page.
What you can do after
Build it from scratch by attaching an open shadow root in a custom element constructor and rendering component content into it.

Read how Web Component Development with Modern Libraries and Tooling explains Shadow DOM →

Vanilla Web

Shadow DOM is a web platform feature for attaching an encapsulated DOM tree to an element.

How it is used
Encapsulates component markup and styles so page selectors and DOM traversal do not accidentally disrupt internal structure.
How deep it goes
Works through root attachment, open and closed modes, scoped styling, public hooks, and tests; does not detail template implementation.
Examples
Uses an open-root component with isolated button styles, a host display rule, and tests querying a button and assigned slot elements.
What you can do after
Build it from scratch with attachShadow(), then define styling hooks and test internal nodes or slot assignments.

Read how Vanilla Web explains Shadow DOM →

CSS in Depth, Second Edition

Shadow DOM is a web platform mechanism that creates an isolated DOM subtree with encapsulated structure and styles.

How it is used
Isolates web-component structure and styles from the surrounding page when a component must remain self-contained.
How deep it goes
Contrasts isolation and cascade behavior with CSS scope but stops short of implementation because JavaScript-driven details are outside treatment.
Examples
Uses an embedded social-media widget as an example of a reusable component requiring identical appearance across websites.
What you can do after
Evaluate whether strong component isolation or cooperative page-wide styling better fits a widget or module.

Read how CSS in Depth, Second Edition explains Shadow DOM →

What to know first

Related concepts

Questions about Shadow DOM

What is Shadow DOM?

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.

Which Manning books explain Shadow DOM?

Web Components in Action, Web Component Development with Modern Libraries and Tooling, Vanilla Web and CSS in Depth, Second Edition.

What should I know before learning Shadow DOM?

Manning books that teach Shadow DOM usually introduce CSS, accessor method, attribute and Document Object Model first.

What is the difference between Shadow DOM and Bootstrap?

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. Bootstrap is an open-source front-end toolkit providing reusable HTML, CSS, and JavaScript components, styles, and responsive layout utilities for web interfaces.

What is Shadow DOM part of?

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

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.