getHTML()Baseline · Newly available
The getHTML() method of Element and ShadowRoot objects serializes an element's DOM to an HTML string.
Works in the latest version of every major browser, but older devices may not support it yet. Baseline since Sep 16, 2024.
Browser support
DesktopChrome
1–124Not supported
125+Supportedsince May 14, 2024
Current: 155Edge
12–124Not supported
125+Supportedsince May 17, 2024
Current: 154Firefox
1–127Not supported
128+Supportedsince Jul 9, 2024
Current: 157Safari
1–17.6Not supported
18+Supportedsince Sep 16, 2024
Current: 27MobileChrome Android
18–124Not supported
125+Supportedsince May 14, 2024
Current: 155Firefox Android
4–127Not supported
128+Supportedsince Jul 9, 2024
Current: 157Safari iOS
1–17.6Not supported
18+Supportedsince Sep 16, 2024
Current: 27How to use
Every current browser supports this, but it only became Baseline on Sep 16, 2024. Use it as a progressive enhancement, or keep a fallback if you support older devices.
Example
Full syntax and examples are on MDN: getHTML.
Feature detection
JS · check before using
if ("Element" in globalThis && "getHTML" in Element.prototype) {
// Element.getHTML is available
}Specification
Sub-features
Support for each part of the feature (2). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| Element.getHTML | 125 | 125 | 128 | 18 | 125 | 128 | 18 |
| ShadowRoot.getHTML | 125 | 125 | 128 | 18 | 125 | 128 | 18 |