Favorites

DOM DocumentFragment Interface

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
DocumentFragment
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

A DocumentFragment is a lightweight container for DOM nodes that isn't part of the page. Building elements in a fragment and adding it in one go is efficient.

Description

A DocumentFragment is a minimal document object with no parent: a place to build a group of nodes off-screen. When you append a fragment to the page, its children are moved in and the fragment is left empty. Adding many elements through a single fragment means the page is only updated once.

Create one with document.createDocumentFragment() or new DocumentFragment(). The content of a <template> element is also a fragment, which you can clone with cloneNode(true).

Fragments are also used by the <template> element, whose content property holds an inert fragment: scripts don't run, images don't load and styles don't apply until a copy is inserted into the page. Like documents, fragments support querySelector(), querySelectorAll(), getElementById(), append() and prepend(), so you can find and change content inside them before inserting it.

Inheritance

DocumentFragment inherits properties and methods from Node.

Example

<ul id="list"></ul>
const list = document.getElementById('list');
const frag = document.createDocumentFragment();
['Red', 'Green', 'Blue'].forEach(color => {
  const li = document.createElement('li');
  li.textContent = color;
  frag.appendChild(li);
});
list.appendChild(frag);
console.log(list.children.length, frag.childNodes.length);

Browser Support

The following information will show you the current browser support for the DocumentFragment interface. Hover over a browser icon to see the version that first introduced support for this interface.

This interface is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee