Favorites

DOM Document.createDocumentFragment() Method

☕
Enjoying this site?

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

Buy us a coffee
Document.createDocumentFragment()
DOM Document MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The createDocumentFragment() method creates an empty DocumentFragment, an off-screen container for building groups of elements.

Description

The createDocumentFragment() method returns a new, empty DocumentFragment. Build a set of elements inside it, then insert the fragment in one step; its children move into the page and the fragment becomes empty. new DocumentFragment() does the same.

Modern browsers already batch DOM updates, so fragments matter less for performance than they once did, but they're still a clear way to assemble a group of elements before adding them in one place. Methods such as append() also accept several nodes at once, which can make a fragment unnecessary for small groups.

A fragment can be appended only once usefully, since its children move out when it's inserted. To insert the same content in several places, clone the fragment with cloneNode(true) for each one.

Syntax

document.createDocumentFragment()

Return Value

A new, empty DocumentFragment.

Example

<ol id="list"></ol>
const frag = document.createDocumentFragment();
for (let i = 1; i <= 5; i++) {
  const li = document.createElement('li');
  li.textContent = 'Row ' + i;
  frag.append(li);
}
document.getElementById('list').append(frag);
console.log(document.querySelectorAll('#list li').length);

Browser Support

The following information will show you the current browser support for the Document.createDocumentFragment() method. Hover over a browser icon to see the version that first introduced support for this method.

This method 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