Favorites

DOM Document.createElement() Method

☕
Enjoying this site?

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

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

The createElement() method creates a new HTML element, which you can then fill in and add to the page.

Description

The createElement() method creates a new element of the given type. It exists only in memory until you add it to the page with a method such as append(), appendChild() or before(). Set its content with textContent and its attributes with properties or setAttribute().

Building elements this way is safer than assembling HTML strings for innerHTML, because text is never parsed as markup. For many elements, build them in a DocumentFragment and add them together.

Tag names are case-insensitive for HTML documents. Unknown tag names create HTMLUnknownElement objects, while names containing a hyphen create custom elements, upgraded automatically if they've been defined. For SVG, use createElementNS('http://www.w3.org/2000/svg', 'circle'), because createElement() creates HTML elements.

Syntax

document.createElement(tagName)

Parameters

  • tagNameThe type of element to create, such as "div" or "li".

Return Value

The new element, not yet in the document.

Example

<ul id="list"></ul>
const list = document.getElementById('list');
for (const name of ['Sam', 'Alex <b>']) {
  const li = document.createElement('li');
  li.textContent = name;          // safe, even with < >
  li.className = 'person';
  list.append(li);
}
console.log(list.innerHTML);

Browser Support

The following information will show you the current browser support for the Document.createElement() 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