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.
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.
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.
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.
What to know first
- CSSCSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
- accessor methodAn accessor method or function is a callable that reads, computes, or assigns a value associated with a property, field, or data element.
- attributeAn attribute is a named property or piece of information associated with an entity, object, or structured data item.
- Document Object ModelThe Document Object Model is a platform-independent programming interface that represents a document as a structured tree of nodes and provides ways to access and modify its content and structure.
Related concepts
- Web Componentsused by · Web Components are browser standards and APIs, including custom elements and shadow DOM, for creating reusable web interface elements with encapsulated structure, presentation, and behavior.
- shadow rootpart of · A shadow root is the root node of an encapsulated Shadow DOM subtree attached to a host element.
- CSS variableused by · A CSS custom property is an author-defined property, typically named with a leading double hyphen, whose value can be inherited and referenced in other declarations.
- encapsulationimplements · Encapsulation is a software design principle that contains data and implementation details behind a controlled interface, restricting direct access to internal state.
- Bootstrapcontrasts with · Bootstrap is an open-source front-end toolkit providing reusable HTML, CSS, and JavaScript components, styles, and responsive layout utilities for web interfaces.
- CSSused by · CSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
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.



