DOM fragment
A DOM fragment is a lightweight, detached node that can hold a subtree of nodes independently of a document tree.
Web Components in Action
A document fragment is a lightweight DOM node that can contain a subtree of nodes without itself being part of a document tree.
- How it is used
- Uses fragments to assemble reusable HTML and batch DOM insertion, especially when templates or repeated content are involved.
- How deep it goes
- Explains construction, child movement, and insertion performance, but stops short of broader DOM implementation internals.
- Examples
- Demonstrates five generated paragraphs, template content cloning, and inspection of shadow roots in browser developer tools.
- What you can do after
- Apply it via JavaScript DOM APIs to build node groups and insert them into a document with one append operation.
Vanilla Web
A lightweight DOM container that holds a subtree of nodes without being part of the document tree itself.
- How it is used
- Buffers DOM nodes for a grouped insertion and holds template markup until it is cloned for use.
- How deep it goes
- Explains child transfer, template ownership, deep cloning, importing, and listener caveats without detailing browser internals.
- Examples
- Uses repeated table rows, cards, tooltips, and component markup as template candidates, alongside buffered multi-node insertion.
- What you can do after
- Build it from scratch with native DOM creation APIs, or clone template content before inserting reusable nodes.
Secrets of the JavaScript Ninja, Second Edition
A lightweight, detached portion of a DOM tree that can be manipulated separately before being inserted into a document.
- How it is used
- Supports efficient insertion of generated HTML into one or more locations in a document.
- How deep it goes
- Defines fragments as node containers and demonstrates adding, inserting, and cloning them.
- Examples
- Demonstrates building nodes from an HTML string and inserting a fragment into multiple document locations.
- What you can do after
- Apply it via document.createDocumentFragment() to batch node insertion and clone content for additional targets.
Read how Secrets of the JavaScript Ninja, Second Edition explains DOM fragment →
What to know first
- 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
- shadow rootincludes · A shadow root is the root node of an encapsulated Shadow DOM subtree attached to a host element.
- HTML template elementused by · The HTML template element holds inert markup that can be cloned and inserted into a document.
- documentuses · A web document is a structured HTML or XML resource represented by a document tree that browser APIs expose for inspection and manipulation.
- reflowaddresses · Reflow is the recalculation or rearrangement of document content and layout to accommodate changes in content, styling, or available display space.
- template content propertyproduced by · The template content property returns an HTML template element’s stored contents as a DocumentFragment.
Questions about DOM fragment
What is DOM fragment?
A DOM fragment is a lightweight, detached node that can hold a subtree of nodes independently of a document tree.
Which Manning books explain DOM fragment?
Web Components in Action, Vanilla Web and Secrets of the JavaScript Ninja, Second Edition.
What should I know before learning DOM fragment?
Manning books that teach DOM fragment usually introduce Document Object Model and DOM node first.
What kinds of DOM fragment are there?
Kinds of DOM fragment include shadow root.
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.


