CKTIS / JavaScript
document.createElement — creating a DOM element
document.createElement creates a new DOM element with the specified name. It does not automatically insert it into the document.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
document.createElement(localName)
document.createElement(localName, options)document.createElement(localName, options) returns a new element without a parent. The localName argument is an element name, not HTML markup. Set content through textContent and insert the element separately, for example with appendChild.
In an HTML document, the name is converted to ASCII lowercase. An invalid name throws a DOMException named InvalidCharacterError. Use createElementNS to explicitly choose a namespace.
In the optional options argument, is specifies the registered name of a customized built-in element that extends the built-in element named by localName. To create an autonomous custom element, pass its registered name directly as localName, not as options.is. Safari does not support customized built-in elements, so this use of options.is does not work in all browsers.
The example shows only the one-argument call, without options. It requires a browser HTML document; JavaScript support alone does not guarantee that document exists.
Examples
const element = document.createElement("DIV");
element.textContent = "Hello";
console.log(element.localName);
console.log(element.textContent);
console.log(element.parentNode === null);Result
div Hello true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.