{"doc":{"body":[{"type":"prose","value":{"id":null,"title":null,"isH3":false,"content":"<p>The <strong><code>createElement()</code></strong> method of the <a href=\"/en-US/docs/Web/API/Document\"><code>Document</code></a> interface creates a new <a href=\"/en-US/docs/Web/API/HTMLElement\"><code>HTMLElement</code></a> that has the specified <code>localName</code>.</p>\n<p>If <code>localName</code> isn't recognized, the method creates an <a href=\"/en-US/docs/Web/API/HTMLUnknownElement\"><code>HTMLUnknownElement</code></a>.</p>"}},{"type":"prose","value":{"id":"syntax","title":"Syntax","isH3":false,"content":"<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>createElement(localName)\ncreateElement(localName, options)\n</code></pre></div>"}},{"type":"prose","value":{"id":"parameters","title":"Parameters","isH3":true,"content":"<dl>\n<dt id=\"localname\"><a href=\"#localname\"><code>localName</code></a></dt>\n<dd>\n<p>A string that specifies the type of element to be created.\nDon't use qualified names (like \"html:a\") with this method.\nWhen called on an HTML document, <code>createElement()</code> converts <code>localName</code> to lowercase before creating the element.\nIn Firefox, Opera, and Chrome, <code>createElement(null)</code> works like <code>createElement(\"null\")</code>.</p>\n</dd>\n<dt id=\"options\"><a href=\"#options\"><code>options</code> <span class=\"badge inline optional\">Optional</span></a></dt>\n<dd>\n<p>An object with the following optional properties (note that only one of <code>is</code> and <code>customElementRegistry</code> may be set):</p>\n<dl>\n<dt id=\"is\"><a href=\"#is\"><code>is</code> <span class=\"badge inline optional\">Optional</span></a></dt>\n<dd>\n<p>A string defining the tag name for a custom element previously defined using <a href=\"/en-US/docs/Web/API/CustomElementRegistry/define\" title=\"customElements.define()\"><code>customElements.define()</code></a>.\nThe new element will be given an <code>is</code> attribute whose value is the custom element's tag name.\nSee <a href=\"#web_component_example\">Web component example</a> for more details.</p>\n</dd>\n<dt id=\"customelementregistry\"><a href=\"#customelementregistry\"><code>customElementRegistry</code> <span class=\"badge inline optional\">Optional</span></a></dt>\n<dd>\n<p>A <a href=\"/en-US/docs/Web/API/CustomElementRegistry\"><code>CustomElementRegistry</code></a> that sets the <a href=\"/en-US/docs/Web/API/Web_components/Using_custom_elements#scoped_custom_element_registries\">Scoped custom element registry</a> of a custom element.</p>\n</dd>\n</dl>\n</dd>\n</dl>"}},{"type":"prose","value":{"id":"return_value","title":"Return value","isH3":true,"content":"<p>The new <a href=\"/en-US/docs/Web/API/Element\"><code>Element</code></a>.</p>\n<div class=\"notecard note\">\n<p><strong>Note:</strong>\nA new <a href=\"/en-US/docs/Web/API/HTMLElement\" title=\"HTMLElement\">HTMLElement</a> is returned if the document is an <a href=\"/en-US/docs/Web/API/HTMLDocument\" title=\"HTMLDocument\">HTMLDocument</a>, which is the most common case.\nOtherwise a new <a href=\"/en-US/docs/Web/API/Element\" title=\"Element\">Element</a> is returned.</p>\n</div>"}},{"type":"prose","value":{"id":"exceptions","title":"Exceptions","isH3":true,"content":"<dl>\n<dt id=\"invalidcharactererror\"><code>InvalidCharacterError</code> <a href=\"/en-US/docs/Web/API/DOMException\"><code>DOMException</code></a></dt>\n<dd>\n<p>Thrown if the <a href=\"#localname\"><code>localName</code></a> value is not a valid element name.\nA string is a valid element name if its length is at least 1 and:</p>\n<ul>\n<li>it starts with an alphabet character and does not contain ASCII whitespace, <code>NULL</code>, <code>/</code>, or <code>&gt;</code> (U+0000, U+002F, or U+003E, respectively).</li>\n<li>it starts with <code>:</code> (U+003A), <code>_</code> (U+005F), or any characters in the range U+0080 to U+10FFFF (inclusive), <em>and</em> the remaining code points only include those same characters along with the ASCII alphanumeric characters, <code>-</code> (U+002D), and <code>.</code> (U+002E),</li>\n</ul>\n<div class=\"notecard note\">\n<p><strong>Note:</strong>\nEarlier versions of the specification were more restrictive, requiring that the <code>localName</code> be a valid <a href=\"https://www.w3.org/TR/xml/#dt-name\" class=\"external\" target=\"_blank\" title=\"External link (opens in new tab)\">XML name</a>.</p>\n</div>\n</dd>\n<dt id=\"notsupportederror\"><code>NotSupportedError</code> <a href=\"/en-US/docs/Web/API/DOMException\"><code>DOMException</code></a></dt>\n<dd>\n<p>Thrown if both the <a href=\"#is\"><code>is</code></a> and <a href=\"#customelementregistry\"><code>customElementRegistry</code></a> options are specified.</p>\n</dd>\n</dl>"}},{"type":"prose","value":{"id":"examples","title":"Examples","isH3":false,"content":""}},{"type":"prose","value":{"id":"basic_example","title":"Basic example","isH3":true,"content":"<p>This creates a new <code>&lt;div&gt;</code> and inserts it before the element with the ID <code>div1</code>.</p>\n<h4 id=\"html\">HTML</h4>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">html</span></div><pre class=\"brush: html notranslate live-sample---basic_example\"><code>&lt;!doctype html&gt;\n&lt;html lang=\"en-US\"&gt;\n  &lt;head&gt;\n    &lt;meta charset=\"UTF-8\" /&gt;\n    &lt;title&gt;Working with elements&lt;/title&gt;\n  &lt;/head&gt;\n  &lt;body&gt;\n    &lt;div id=\"div1\"&gt;The text above has been created dynamically.&lt;/div&gt;\n  &lt;/body&gt;\n&lt;/html&gt;\n</code></pre></div>\n<h4 id=\"javascript\">JavaScript</h4>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate live-sample---basic_example\"><code>function addElement() {\n  // create a new div element\n  const newDiv = document.createElement(\"div\");\n\n  // and give it some content\n  const newContent = document.createTextNode(\"Hi there and greetings!\");\n\n  // add the text node to the newly created div\n  newDiv.appendChild(newContent);\n\n  // add the newly created element and its content into the DOM\n  const currentDiv = document.getElementById(\"div1\");\n  document.body.insertBefore(newDiv, currentDiv);\n}\n\naddElement();\n</code></pre></div>\n<h4 id=\"result\">Result</h4>\n<div class=\"code-example\"><div class=\"example-header\"></div><iframe class=\"sample-code-frame\" title=\"Basic example sample\" id=\"frame_basic_example\" width=\"500\" height=\"80\" src=\"about:blank\" data-live-path=\"/en-US/docs/Web/API/Document/createElement/\" data-live-id=\"basic_example\" sandbox=\"allow-same-origin allow-scripts\" loading=\"lazy\"></iframe></div>"}},{"type":"prose","value":{"id":"web_component_example","title":"Web component example","isH3":true,"content":"<div class=\"notecard note\">\n<p><strong>Note:</strong>\nCheck the <a href=\"#browser_compatibility\">browser compatibility</a> section for support, and the <a href=\"/en-US/docs/Web/HTML/Reference/Global_attributes/is\"><code>is</code></a> attribute reference for caveats on implementation reality of customized built-in elements.</p>\n</div>\n<p>The following example snippet is taken from our <a href=\"https://github.com/mdn/web-components-examples/tree/main/expanding-list-web-component\" class=\"external\" target=\"_blank\" title=\"External link (opens in new tab)\">expanding-list-web-component</a> example (<a href=\"https://mdn.github.io/web-components-examples/expanding-list-web-component/\" class=\"external\" target=\"_blank\" title=\"External link (opens in new tab)\">see it live also</a>). In this case, our custom element extends the <a href=\"/en-US/docs/Web/API/HTMLUListElement\"><code>HTMLUListElement</code></a>, which represents the <a href=\"/en-US/docs/Web/HTML/Reference/Elements/ul\"><code>&lt;ul&gt;</code></a> element.</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>// Create a class for the element\nclass ExpandingList extends HTMLUListElement {\n  constructor() {\n    // Always call super first in constructor\n    super();\n\n    // constructor definition left out for brevity\n    // …\n  }\n}\n\n// Define the new element\ncustomElements.define(\"expanding-list\", ExpandingList, { extends: \"ul\" });\n</code></pre></div>\n<p>If we wanted to create an instance of this element programmatically, we'd use a call along the following lines:</p>\n<div class=\"code-example\"><div class=\"example-header\"><span class=\"language-name\">js</span></div><pre class=\"brush: js notranslate\"><code>let expandingList = document.createElement(\"ul\", { is: \"expanding-list\" });\n</code></pre></div>\n<p>The new element will be given an <a href=\"/en-US/docs/Web/HTML/Reference/Global_attributes/is\"><code>is</code></a> attribute whose value is the custom element's tag name.</p>\n<div class=\"notecard note\">\n<p><strong>Note:</strong>\nFor backwards compatibility, some browsers will allow you to pass a string here instead of an object, where the string's value is the custom element's tag name.</p>\n</div>"}},{"type":"specifications","value":{"id":"specifications","title":"Specifications","isH3":false,"specifications":[{"bcdSpecificationURL":"https://dom.spec.whatwg.org/#ref-for-dom-document-createelement①","title":"DOM"}],"query":"api.Document.createElement"}},{"type":"browser_compatibility","value":{"id":"browser_compatibility","title":"Browser compatibility","isH3":false,"query":"api.Document.createElement"}},{"type":"prose","value":{"id":"see_also","title":"See also","isH3":false,"content":"<ul>\n<li><a href=\"/en-US/docs/Web/API/Node/removeChild\"><code>Node.removeChild()</code></a></li>\n<li><a href=\"/en-US/docs/Web/API/Node/replaceChild\"><code>Node.replaceChild()</code></a></li>\n<li><a href=\"/en-US/docs/Web/API/Node/appendChild\"><code>Node.appendChild()</code></a></li>\n<li><a href=\"/en-US/docs/Web/API/Node/insertBefore\"><code>Node.insertBefore()</code></a></li>\n<li><a href=\"/en-US/docs/Web/API/Node/hasChildNodes\"><code>Node.hasChildNodes()</code></a></li>\n<li><a href=\"/en-US/docs/Web/API/Document/createElementNS\"><code>document.createElementNS()</code></a> — to explicitly specify the namespace URI for the element.</li>\n</ul>"}}],"isActive":true,"isMarkdown":true,"isTranslated":false,"locale":"en-US","mdn_url":"/en-US/docs/Web/API/Document/createElement","modified":"2026-04-06T19:43:24.000Z","native":"English (US)","noIndexing":false,"other_translations":[{"locale":"en-US","title":"Document: createElement() method","native":"English (US)"},{"locale":"de","title":"Dokument: createElement() Methode","native":"Deutsch"},{"locale":"es","title":"Document.createElement()","native":"Español"},{"locale":"fr","title":"Document : méthode createElement()","native":"Français"},{"locale":"ja","title":"Document: createElement() メソッド","native":"日本語"},{"locale":"ko","title":"Document.createElement()","native":"한국어"},{"locale":"pt-BR","title":"Document: createElement() method","native":"Português (do Brasil)"},{"locale":"ru","title":"document.createElement","native":"Русский"},{"locale":"zh-CN","title":"Document：createElement() 方法","native":"中文 (简体)"},{"locale":"zh-TW","title":"Document：createElement() 方法","native":"正體中文 (繁體)"}],"pageTitle":"Document: createElement() method - Web APIs | MDN","parents":[{"uri":"/en-US/docs/Web","title":"Web"},{"uri":"/en-US/docs/Web/API","title":"Web APIs"},{"uri":"/en-US/docs/Web/API/Document","title":"Document"},{"uri":"/en-US/docs/Web/API/Document/createElement","title":"createElement()"}],"popularity":0.06832777881080772,"short_title":"createElement()","sidebarHTML":"<ol><li class=\"section\"><a href=\"/en-US/docs/Web/API/Document_Object_Model\">Document Object Model (DOM)</a></li><li class=\"section\"><a href=\"/en-US/docs/Web/API/Document\"><code>Document</code></a></li><li><details open=\"\"><summary><span>Constructor</span></summary><ol><li><a href=\"/en-US/docs/Web/API/Document/Document\"><code>Document()</code></a></li></ol></details></li><li><details open=\"\"><summary><span>Instance properties</span></summary><ol><li><a href=\"/en-US/docs/Web/API/Document/activeElement\"><code>activeElement</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/activeViewTransition\"><code>activeViewTransition</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/adoptedStyleSheets\"><code>adoptedStyleSheets</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/alinkColor\"><code>alinkColor</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/all\"><code>all</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/anchors\"><code>anchors</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/applets\"><code>applets</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/bgColor\"><code>bgColor</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/body\"><code>body</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/characterSet\"><code>characterSet</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/childElementCount\"><code>childElementCount</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/children\"><code>children</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/compatMode\"><code>compatMode</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/contentType\"><code>contentType</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/cookie\"><code>cookie</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/currentScript\"><code>currentScript</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/customElementRegistry\"><code>customElementRegistry</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/defaultView\"><code>defaultView</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/designMode\"><code>designMode</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/dir\"><code>dir</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/doctype\"><code>doctype</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/documentElement\"><code>documentElement</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/documentURI\"><code>documentURI</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/domain\"><code>domain</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/embeds\"><code>embeds</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/featurePolicy\"><code>featurePolicy</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-experimental\" title=\"Experimental. Expect behavior to change in the future.\" aria-label=\"Experimental\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/fgColor\"><code>fgColor</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/firstElementChild\"><code>firstElementChild</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/fonts\"><code>fonts</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/forms\"><code>forms</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/fragmentDirective\"><code>fragmentDirective</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/fullscreen\"><code>fullscreen</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/fullscreenElement\"><code>fullscreenElement</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/fullscreenEnabled\"><code>fullscreenEnabled</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/head\"><code>head</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/hidden\"><code>hidden</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/images\"><code>images</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/implementation\"><code>implementation</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/lastElementChild\"><code>lastElementChild</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/lastModified\"><code>lastModified</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/lastStyleSheetSet\"><code>lastStyleSheetSet</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/linkColor\"><code>linkColor</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/links\"><code>links</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/location\"><code>location</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/pictureInPictureElement\"><code>pictureInPictureElement</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/pictureInPictureEnabled\"><code>pictureInPictureEnabled</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/plugins\"><code>plugins</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/pointerLockElement\"><code>pointerLockElement</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/preferredStyleSheetSet\"><code>preferredStyleSheetSet</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/prerendering\"><code>prerendering</code><span role=\"img\" class=\"icon icon-experimental\" title=\"Experimental. Expect behavior to change in the future.\" aria-label=\"Experimental\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/readyState\"><code>readyState</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/referrer\"><code>referrer</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/rootElement\"><code>rootElement</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/scripts\"><code>scripts</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/scrollingElement\"><code>scrollingElement</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/selectedStyleSheetSet\"><code>selectedStyleSheetSet</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/styleSheets\"><code>styleSheets</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/styleSheetSets\"><code>styleSheetSets</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/timeline\"><code>timeline</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/title\"><code>title</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/URL\"><code>URL</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/visibilityState\"><code>visibilityState</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/vlinkColor\"><code>vlinkColor</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/xmlEncoding\"><code>xmlEncoding</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/xmlVersion\"><code>xmlVersion</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li></ol></details></li><li><details open=\"\"><summary><span>Static methods</span></summary><ol><li><a href=\"/en-US/docs/Web/API/Document/parseHTML_static\"><code>parseHTML()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/parseHTMLUnsafe_static\"><code>parseHTMLUnsafe()</code></a></li></ol></details></li><li><details open=\"\"><summary><span>Instance methods</span></summary><ol><li><a href=\"/en-US/docs/Web/API/Document/adoptNode\"><code>adoptNode()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/append\"><code>append()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/ariaNotify\"><code>ariaNotify()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/browsingTopics\"><code>browsingTopics()</code><span role=\"img\" class=\"icon icon-baseline removing\" title=\"Deprecated. Pending removal from browsers.\" aria-label=\"Deprecated, pending removal\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/caretPositionFromPoint\"><code>caretPositionFromPoint()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/caretRangeFromPoint\"><code>caretRangeFromPoint()</code><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/clear\"><code>clear()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/close\"><code>close()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/createAttribute\"><code>createAttribute()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/createAttributeNS\"><code>createAttributeNS()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/createCDATASection\"><code>createCDATASection()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/createComment\"><code>createComment()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/createDocumentFragment\"><code>createDocumentFragment()</code></a></li><li><em><a href=\"/en-US/docs/Web/API/Document/createElement\" aria-current=\"page\"><code>createElement()</code></a></em></li><li><a href=\"/en-US/docs/Web/API/Document/createElementNS\"><code>createElementNS()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/createEvent\"><code>createEvent()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/createExpression\"><code>createExpression()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/createNodeIterator\"><code>createNodeIterator()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/createNSResolver\"><code>createNSResolver()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/createProcessingInstruction\"><code>createProcessingInstruction()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/createRange\"><code>createRange()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/createTextNode\"><code>createTextNode()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/createTouch\"><code>createTouch()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/createTouchList\"><code>createTouchList()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/createTreeWalker\"><code>createTreeWalker()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/elementFromPoint\"><code>elementFromPoint()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/elementsFromPoint\"><code>elementsFromPoint()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/enableStyleSheetsForSet\"><code>enableStyleSheetsForSet()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/evaluate\"><code>evaluate()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/execCommand\"><code>execCommand()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/exitFullscreen\"><code>exitFullscreen()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/exitPictureInPicture\"><code>exitPictureInPicture()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/exitPointerLock\"><code>exitPointerLock()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/getAnimations\"><code>getAnimations()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/getElementById\"><code>getElementById()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/getElementsByClassName\"><code>getElementsByClassName()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/getElementsByName\"><code>getElementsByName()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/getElementsByTagName\"><code>getElementsByTagName()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/getElementsByTagNameNS\"><code>getElementsByTagNameNS()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/getSelection\"><code>getSelection()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/hasFocus\"><code>hasFocus()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/hasPrivateToken\"><code>hasPrivateToken()</code><span role=\"img\" class=\"icon icon-experimental\" title=\"Experimental. Expect behavior to change in the future.\" aria-label=\"Experimental\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/hasRedemptionRecord\"><code>hasRedemptionRecord()</code><span role=\"img\" class=\"icon icon-experimental\" title=\"Experimental. Expect behavior to change in the future.\" aria-label=\"Experimental\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/hasStorageAccess\"><code>hasStorageAccess()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/hasUnpartitionedCookieAccess\"><code>hasUnpartitionedCookieAccess()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/importNode\"><code>importNode()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/moveBefore\"><code>moveBefore()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/mozSetImageElement\"><code>mozSetImageElement()</code><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/open\"><code>open()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/prepend\"><code>prepend()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/queryCommandEnabled\"><code>queryCommandEnabled()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/queryCommandState\"><code>queryCommandState()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/queryCommandSupported\"><code>queryCommandSupported()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/querySelector\"><code>querySelector()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/querySelectorAll\"><code>querySelectorAll()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/releaseCapture\"><code>releaseCapture()</code><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/replaceChildren\"><code>replaceChildren()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/requestStorageAccess\"><code>requestStorageAccess()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/requestStorageAccessFor\"><code>requestStorageAccessFor()</code><span role=\"img\" class=\"icon icon-baseline removing\" title=\"Deprecated. Pending removal from browsers.\" aria-label=\"Deprecated, pending removal\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/startViewTransition\"><code>startViewTransition()</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/write\"><code>write()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/writeln\"><code>writeln()</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li></ol></details></li><li><details open=\"\"><summary><span>Events</span></summary><ol><li><a href=\"/en-US/docs/Web/API/Document/afterscriptexecute_event\"><code>afterscriptexecute</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/beforescriptexecute_event\"><code>beforescriptexecute</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/DOMContentLoaded_event\"><code>DOMContentLoaded</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/fullscreenchange_event\"><code>fullscreenchange</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/fullscreenerror_event\"><code>fullscreenerror</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/pointerlockchange_event\"><code>pointerlockchange</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/pointerlockerror_event\"><code>pointerlockerror</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/prerenderingchange_event\"><code>prerenderingchange</code><span role=\"img\" class=\"icon icon-experimental\" title=\"Experimental. Expect behavior to change in the future.\" aria-label=\"Experimental\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/readystatechange_event\"><code>readystatechange</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/scroll_event\"><code>scroll</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/scrollend_event\"><code>scrollend</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/scrollsnapchange_event\"><code>scrollsnapchange</code><span role=\"img\" class=\"icon icon-experimental\" title=\"Experimental. Expect behavior to change in the future.\" aria-label=\"Experimental\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/scrollsnapchanging_event\"><code>scrollsnapchanging</code><span role=\"img\" class=\"icon icon-experimental\" title=\"Experimental. Expect behavior to change in the future.\" aria-label=\"Experimental\"></span></a></li><li><a href=\"/en-US/docs/Web/API/Document/securitypolicyviolation_event\"><code>securitypolicyviolation</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/selectionchange_event\"><code>selectionchange</code></a></li><li><a href=\"/en-US/docs/Web/API/Document/visibilitychange_event\"><code>visibilitychange</code></a></li></ol></details></li><li><details open=\"\"><summary><span>Inheritance</span></summary><ol><li><a href=\"/en-US/docs/Web/API/Node\"><code>Node</code></a></li><li><a href=\"/en-US/docs/Web/API/EventTarget\"><code>EventTarget</code></a></li></ol></details></li><li><details open=\"\"><summary><span>Related pages for DOM</span></summary><ol><li><a href=\"/en-US/docs/Web/API/AbortController\"><code>AbortController</code></a></li><li><a href=\"/en-US/docs/Web/API/AbortSignal\"><code>AbortSignal</code></a></li><li><a href=\"/en-US/docs/Web/API/AbstractRange\"><code>AbstractRange</code></a></li><li><a href=\"/en-US/docs/Web/API/Attr\"><code>Attr</code></a></li><li><a href=\"/en-US/docs/Web/API/CDATASection\"><code>CDATASection</code></a></li><li><a href=\"/en-US/docs/Web/API/CharacterData\"><code>CharacterData</code></a></li><li><a href=\"/en-US/docs/Web/API/Comment\"><code>Comment</code></a></li><li><a href=\"/en-US/docs/Web/API/CustomEvent\"><code>CustomEvent</code></a></li><li><a href=\"/en-US/docs/Web/API/DOMError\"><code>DOMError</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span><span role=\"img\" class=\"icon icon-nonstandard\" title=\"Non-standard. Check cross-browser support before using.\" aria-label=\"Non-standard\"></span></a></li><li><a href=\"/en-US/docs/Web/API/DOMException\"><code>DOMException</code></a></li><li><a href=\"/en-US/docs/Web/API/DOMImplementation\"><code>DOMImplementation</code></a></li><li><a href=\"/en-US/docs/Web/API/DOMParser\"><code>DOMParser</code></a></li><li><a href=\"/en-US/docs/Web/API/DOMTokenList\"><code>DOMTokenList</code></a></li><li><a href=\"/en-US/docs/Web/API/DocumentFragment\"><code>DocumentFragment</code></a></li><li><a href=\"/en-US/docs/Web/API/DocumentType\"><code>DocumentType</code></a></li><li><a href=\"/en-US/docs/Web/API/Element\"><code>Element</code></a></li><li><a href=\"/en-US/docs/Web/API/Event\"><code>Event</code></a></li><li><a href=\"/en-US/docs/Web/API/EventTarget\"><code>EventTarget</code></a></li><li><a href=\"/en-US/docs/Web/API/HTMLCollection\"><code>HTMLCollection</code></a></li><li><a href=\"/en-US/docs/Web/API/MutationObserver\"><code>MutationObserver</code></a></li><li><a href=\"/en-US/docs/Web/API/MutationRecord\"><code>MutationRecord</code></a></li><li><a href=\"/en-US/docs/Web/API/NamedNodeMap\"><code>NamedNodeMap</code></a></li><li><a href=\"/en-US/docs/Web/API/Node\"><code>Node</code></a></li><li><a href=\"/en-US/docs/Web/API/NodeIterator\"><code>NodeIterator</code></a></li><li><a href=\"/en-US/docs/Web/API/NodeList\"><code>NodeList</code></a></li><li><a href=\"/en-US/docs/Web/API/ProcessingInstruction\"><code>ProcessingInstruction</code></a></li><li><a href=\"/en-US/docs/Web/API/QuotaExceededError\"><code>QuotaExceededError</code></a></li><li><a href=\"/en-US/docs/Web/API/Range\"><code>Range</code></a></li><li><a href=\"/en-US/docs/Web/API/ShadowRoot\"><code>ShadowRoot</code></a></li><li><a href=\"/en-US/docs/Web/API/StaticRange\"><code>StaticRange</code></a></li><li><a href=\"/en-US/docs/Web/API/Text\"><code>Text</code></a></li><li><a href=\"/en-US/docs/Web/API/TreeWalker\"><code>TreeWalker</code></a></li><li><a href=\"/en-US/docs/Web/API/XMLDocument\"><code>XMLDocument</code></a></li><li><a href=\"/en-US/docs/Web/API/XPathEvaluator\"><code>XPathEvaluator</code></a></li><li><a href=\"/en-US/docs/Web/API/XPathExpression\"><code>XPathExpression</code></a></li><li><a href=\"/en-US/docs/Web/API/XPathResult\"><code>XPathResult</code></a></li><li><a href=\"/en-US/docs/Web/API/XSLTProcessor\"><code>XSLTProcessor</code><span role=\"img\" class=\"icon icon-baseline discouraged\" title=\"Deprecated. Not for use in new websites.\" aria-label=\"Deprecated\"></span></a></li></ol></details></li><li><details open=\"\"><summary><span>Guides</span></summary><ol><li><a href=\"/en-US/docs/Web/API/Document_Object_Model/Anatomy_of_the_DOM\">Anatomy of the DOM</a></li><li><a href=\"/en-US/docs/Web/API/Document_Object_Model/Reflected_attributes\">Attribute reflection</a></li><li><a href=\"/en-US/docs/Web/API/Document_Object_Model/Selection_and_traversal_on_the_DOM_tree\">Selection and traversal on the DOM tree</a></li><li><a href=\"/en-US/docs/Web/API/Document_Object_Model/Building_and_updating_the_DOM_tree\">Building and updating the DOM tree</a></li><li><a href=\"/en-US/docs/Web/API/Document_Object_Model/Events\">Working with events</a></li></ol></details></li></ol>","source":{"folder":"en-us/web/api/document/createelement","github_url":"https://github.com/mdn/content/blob/main/files/en-us/web/api/document/createelement/index.md","last_commit_url":"https://github.com/mdn/content/commit/09d8ff096be97b28ea415fc4c68fb1cff0ff8af9","filename":"index.md"},"summary":"The createElement() method of the Document interface creates a new HTMLElement that has the specified localName.","title":"Document: createElement() method","titleHTML":"Document: createElement() method","toc":[{"text":"Syntax","id":"syntax"},{"text":"Examples","id":"examples"},{"text":"Specifications","id":"specifications"},{"text":"Browser compatibility","id":"browser_compatibility"},{"text":"See also","id":"see_also"}],"fragments":["syntax","parameters","localname","options","is","customelementregistry","return_value","exceptions","invalidcharactererror","notsupportederror","examples","basic_example","html","javascript","result","frame_basic_example","web_component_example","specifications","browser_compatibility","see_also"],"baseline":{"baseline":"high","baseline_low_date":"2015-07-29","baseline_high_date":"2018-01-29","support":{"chrome":"1","chrome_android":"18","edge":"12","firefox":"1","firefox_android":"4","safari":"1","safari_ios":"1"},"asterisk":true,"feature":{"id":"dom","status":{"baseline":"high","baseline_low_date":"2015-07-29","baseline_high_date":"2018-01-29","support":{"chrome":"1","chrome_android":"18","edge":"12","firefox":"1","firefox_android":"4","safari":"1","safari_ios":"1"}},"description_html":"The DOM (Document Object Model) API represents HTML and XML documents as trees of nodes. You can use the API to inspect and modify the structure and content of a document.","name":"DOM"}},"browserCompat":["api.Document.createElement"],"pageType":"web-api-instance-method","status":{"baseline":"high"}},"url":"/en-US/docs/Web/API/Document/createElement","renderer":"Doc"}