Short answer
The DOM is the document tree, and a shadow DOM is a second tree attached to one element. Page CSS and a document query do not see inside it. Open mode exposes shadowRoot, and closed mode returns null, which is not a security boundary. The DOM standard calls the host's tree the light tree. Use a shadow tree for a component's private markup.
Last verified against the sources listed below.
Key takeaways
- A shadow tree's root is a shadow root, attached to a host element in another tree.
- The DOM standard calls the host's node tree the light tree.
- attachShadow mode open exposes shadowRoot. Mode closed returns null, and MDN says that is not a security boundary.
- querySelectorAll on the document does not find nodes inside the shadow tree.
- Page CSS does not style the shadow tree, and shadow CSS does not style the page.
- A template with shadowrootmode can declare the shadow root in HTML.
Shadow DOM vs DOM is the difference between the page’s document tree and a second tree hung off one element. MDN’s shadow DOM guide says you attach that second tree so JavaScript and CSS in the page do not accidentally change a component’s insides.
The document tree is still there. The shadow tree is extra, and it is never alone. Use it when a reusable element must keep its buttons, styles, and markup to itself. Leave ordinary headings and paragraphs in the document tree.
What is shadow DOM vs DOM?
The DOM is the tree of nodes that represents the document. MDN’s guide walks a small HTML fragment from html through head and body down to text nodes. That tree is what document.querySelectorAll searches, and what a stylesheet on the page styles.
A shadow DOM is another tree attached to one element in that document. The element is the shadow host, the inner tree is the shadow tree, and its top node is the shadow root. The shadow boundary is where the inner tree ends and the document tree begins. You create it in script with attachShadow, passing mode: "open" or mode: "closed".
Open mode lets page script read host.shadowRoot and query inside. Closed mode makes shadowRoot return null. MDN says that is a hint to stay out, not a strong security mechanism, because an extension in the page can still get through.
The call is JavaScript. ECMA-262 is the language specification, and the page Ecma publishes for 2026 is the 17th edition, June 2026. The shadow tree itself is defined by the DOM standard, not by that language spec.
What is shadow DOM vs light DOM?
Shadow DOM vs light DOM is the same split, with the DOM standard’s name for the outer side. The DOM standard says a shadow tree is a node tree whose root is a shadow root, and that the node tree of the host is sometimes called the light tree. Authors say light DOM for that outer tree. The spec’s word is light tree.
Children you write between a custom element’s tags live in the light tree, and a slot in the shadow tree is a hole those children can fill. MDN’s slots guide calls nodes that can go into a slot slottable, and a node that has been placed is slotted. The slot attribute matches the slot’s name, and no attribute means the unnamed default slot.
If nobody assigns a child, the slot shows the fallback markup inside it. That fallback lives in the shadow tree. The assigned child does not move its parent pointer. MDN notes that an assigned element still inherits lang and dir from its light-tree parent, while the slot itself inherits inside the shadow tree.
| Piece | Which tree | How you reach it |
|---|---|---|
| Document elements | Light tree, the host’s node tree | document.querySelectorAll |
| Shadow host | Light tree | A normal selector |
| Shadow root and its children | Shadow tree | host.shadowRoot when mode is open |
| Closed shadow root | Shadow tree | shadowRoot is null for page script |
| Slot fallback | Shadow tree | Inside the shadow root |
| Assigned children | Light tree, projected by a slot | The host’s child list, not a move |
When should you choose a shadow tree?
Choose a shadow tree when the element is a component that will be dropped into pages you do not control. MDN’s reason is encapsulation. A page rule for span, or a script that uppercases every span, should not restyle or rewrite the component’s private nodes.
Choose it when the component’s CSS must stay inside. A style element in the shadow tree, or a CSSStyleSheet assigned to adoptedStyleSheets, applies only there. The same sheet can be shared by many shadow roots so the browser parses it once. Page styles do not cross in, and shadow styles do not cross out.
Choose the declarative form when the server should send the tree. The HTML standard defines the shadowrootmode attribute on template as the switch that enables a streaming declarative shadow root. The values match attachShadow: open or closed. After parsing, the template wrapper is gone and a shadow root sits on the parent.
JavaScript is what calls attachShadow or defines the custom element class.
HTML is the document the host lives in.
CSS is what stops at the boundary unless you put it inside the shadow tree.
When should you keep a single document tree?
Keep one tree when the content is the page, not a widget. Headings, paragraphs, and links that should be found by a normal query, styled by the page sheet, and read as the document’s own children do not need a second root.
Keep one tree when you want a parent selector or a page stylesheet to be the styling system. A shadow boundary blocks that on purpose. If the design depends on one cascade for the whole page, a shadow root fights the design.
A generated component is not automatically a shadow tree. The SVG to JSX tool emits a component, which is still script that returns elements into the document tree unless it attaches a shadow root. One document tree is the default, and the second tree is a choice you make on the host.
Frequently asked questions
Does closed mode hide the tree from everyone?
It hides shadowRoot from page script. MDN says passing mode closed makes that property return null, so the page cannot walk in through the host. The same page says you should not treat this as a strong security mechanism, because a browser extension running in the page can still reach the tree. Closed is a signal that page code should stay out. It is not an access-control boundary you can rely on against every caller.
What is a slot?
A slot is a placeholder in the shadow tree. MDN says nodes that can be inserted into slots are slottable, and a node that has been inserted is slotted. You mark the light-tree child with a slot attribute that matches the slot's name. Children with no slot attribute go to the unnamed slot. If nothing is assigned, the slot shows its fallback content. Manual assignment uses HTMLSlotElement.assign when the shadow root's slot assignment is manual.
Can page CSS style a shadow tree?
Not with a normal page selector. MDN's shadow DOM guide shows a span rule on the page that does not change a span inside the shadow tree. A style element inside the shadow tree, or a constructable stylesheet assigned to adoptedStyleSheets, styles that tree only. Those rules do not leak out to the rest of the page. If you need one look for many components, one shared stylesheet can be adopted by each shadow root.
Where do lang and dir come from?
MDN says language and direction normally inherit from the parent. When that parent is a shadow root, they inherit from the shadow host instead. An element assigned to a slot does not change its parent, so it inherits from its parent outside the shadow tree, not from the slot. The slot and its fallback inherit inside the shadow tree like any other element there.
Is a generated component a shadow tree?
Not by itself. A function that returns elements still renders into the document tree unless that component calls attachShadow or ships a template with shadowrootmode. Generating markup does not create a shadow root. The shadow boundary appears only when you attach one. Until then there is one tree, and document.querySelectorAll can see the nodes you added.
Sources
- Using shadow DOM · MDN, 2026
- Using templates and slots · MDN, 2026
- Shadow trees · WHATWG, 2026
- The template element · WHATWG, 2026
- ECMA-262 · Ecma International, 2026