DOM Document.createElement() Method
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
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.
Desktop





Tablets & Mobile





