ShadowRoot: getHTML() method

Baseline 2024
Newly available

Since September 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The getHTML() method of the ShadowRoot interface is used to serialize a shadow root's DOM to an HTML string.

The method provides an options argument that enables the serialization of child nodes that are shadow roots. The options can be used to include nested shadow roots that have been set as serializable, and/or a specified array of ShadowRoot objects, which may be either open or closed.

Without arguments, child nodes that are shadow roots are not serialized, and this method behaves in the same way as reading the value of Element.innerHTML.

Syntax

js
getHTML(options)

Parameters

options Optional

An options object with the following optional parameters:

serializableShadowRoots

A boolean value that specifies whether to include serializable shadow roots. The default value is false.

shadowRoots

An array of ShadowRoot objects to serialize. These are included regardless of whether they are marked as serializable, or if they are open or closed. The default value is an empty array.

Return value

A string that represents the HTML serialization of the shadow root.

Exceptions

None.

Specifications

Specification
HTML
# dom-shadowroot-gethtml

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
getHTML

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See Also