HTML setter methodsLimited availability
The setHTML(), replaceWithHTML(), beforeHTML(), prependHTML(), appendHTML() and afterHTML() DOM methods, and unsafe equivalents, insert HTML into an existing tree.
Not yet supported in all major browsers — check the table and provide a fallback.
Browser support
DesktopChrome
✕Not supportedup to 155
Current: 155Edge
✕Not supportedup to 154
Current: 154Firefox
✕Not supportedup to 157
Current: 157Safari
✕Not supportedup to 27
Current: 27MobileChrome Android
✕Not supportedup to 155
Current: 155Firefox Android
✕Not supportedup to 157
Current: 157Safari iOS
✕Not supportedup to 27
Current: 27How to use
Not supported in Chrome, Edge, Firefox, Safari, Chrome Android, Firefox Android, Safari iOS. Use feature detection below and provide a fallback (or a polyfill) for those browsers.
Example
Full syntax and examples are on MDN: setHTMLUnsafe.
Feature detection
JS · check before using
if ("TrustedHTMLParserOptions" in globalThis) {
// TrustedHTMLParserOptions is available
} else {
// load a polyfill or use a fallback
}Documentation (MDN)
Specification
Sub-features
Support for each part of the feature (33). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| CharacterData.afterHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| CharacterData.afterHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| CharacterData.beforeHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| CharacterData.beforeHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| CharacterData.replaceWithHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| CharacterData.replaceWithHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.afterHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.afterHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.appendHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.appendHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.beforeHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.beforeHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.prependHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.prependHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.replaceWithHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.replaceWithHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| Element.setHTMLUnsafe | 124 | 124 | 123 | 26 | 124 | 123 | 26 |
| Element.setHTMLUnsafe.options_runscripts_parameter | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| ShadowRoot.afterHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| ShadowRoot.afterHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
Show 13 more
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| ShadowRoot.appendHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| ShadowRoot.appendHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| ShadowRoot.beforeHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| ShadowRoot.beforeHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| ShadowRoot.prependHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| ShadowRoot.prependHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| ShadowRoot.replaceWithHTML | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| ShadowRoot.replaceWithHTMLUnsafe | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| ShadowRoot.setHTMLUnsafe | 124 | 124 | 123 | 26 | 124 | 123 | 26 |
| ShadowRoot.setHTMLUnsafe.options_runscripts_parameter | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| TrustedHTMLParserOptions | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| TrustedHTMLParserOptions.runScripts | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |
| TrustedHTMLParserOptions.sanitizer | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ | ✕ |