In JavaScript, the getHTML() method serializes an element’s DOM to an HTML string (MDN). Without options it matches reading innerHTML — shadow roots are not included.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call el.getHTML. Start with this line.
JavaScript
el.getHTML(options?)
Call
What it does
el.getHTML(options?)
Primary signature.
el.getHTML(...)
Call with the arguments your case needs.
Built into the browser. Call getHTML(...) on an Element — no import required.
Library declarations
JavaScript
el.getHTML(options?)
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
HTML string (never throws — MDN)
JavaScript Examples
Example 1 — Basic Serialize
Turn an element’s children into an HTML string.
JavaScript
const el = document.getElementById("box");
if (typeof el.getHTML === "function") {
console.log(el.getHTML());
} else {
console.log(el.innerHTML);
}
Attach a serializable shadow.attachShadow({ serializable: true }).
Default getHTML skips it. Same as innerHTML (MDN).
Opt in with options.serializableShadowRoots: true.
Or pass shadowRoots. Include specific open/closed roots by reference.
Compatibility
Browser Support
Element.getHTML() is Baseline 2024 Newly available (MDN: across browsers since September 2024). Feature-detect and fall back to innerHTML when needed.
✓ Baseline 2024 · Newly available
getHTML()
Serialize an element’s DOM to an HTML string — with optional shadow root inclusion.
NewBaseline 2024
Google ChromeRecent (check MDN)
Supported
Mozilla FirefoxRecent (check MDN)
Supported
Apple SafariRecent (check MDN)
Supported
Microsoft EdgeChromium-based
Supported
OperaChromium-based paths
Supported
Internet ExplorerNot available
Unavailable
getHTML()Newly available
Bottom line: Use getHTML for modern apps that may need shadow serialization; keep an innerHTML fallback for older browsers.
Frequently Asked Questions
It serializes an element’s DOM subtree to an HTML string. Without options, it behaves like reading Element.innerHTML — shadow roots are not included (MDN).
No. MDN marks Element.getHTML() as Baseline 2024 Newly available (across browsers since September 2024). It is not Deprecated, Experimental, or Non-standard. Feature-detect on older browsers.
An optional object with serializableShadowRoots (boolean, default false) and shadowRoots (array of ShadowRoot objects, default []). These control whether and which shadow trees are serialized (MDN).
For plain elements without shadow DOM, getHTML() and innerHTML return the same markup. getHTML() can also include serializable or specified shadow roots — innerHTML never serializes shadow content.
When true, getHTML() includes child shadow roots that were created with serializable: true in attachShadow() (MDN).
No. MDN lists no exceptions for getHTML(). It always returns a string.