Sanitizer APILimited availability
The Sanitizer API customizes the sanitization of HTML parsed and inserted into the DOM in a way that can prevent cross-site scripting attacks. You can use it with DOM APIs that accept a sanitizer option, such as parseHTML() or setHTML().
Not yet supported in all major browsers — check the table and provide a fallback.
Browser support
DesktopChrome
1–145Not supported
146+Supportedsince Mar 10, 2026
Current: 155Edge
12–145Not supported
146+Supportedsince Mar 13, 2026
Current: 154Firefox
1–147Not supported
148+Supportedsince Feb 24, 2026
Current: 157Safari
✕Not supportedup to 27
Current: 27MobileChrome Android
18–145Not supported
146+Supportedsince Mar 10, 2026
Current: 155Firefox Android
4–147Not supported
148+Supportedsince Feb 24, 2026
Current: 157Safari iOS
✕Not supportedup to 27
Current: 27How to use
Not supported in Safari, Safari iOS. Use feature detection below and provide a fallback (or a polyfill) for those browsers.
Example
Full syntax and examples are on MDN: parseHTML static.
Feature detection
JS · check before using
if ("Sanitizer" in globalThis) {
// Sanitizer is available
} else {
// load a polyfill or use a fallback
}Sub-features
Support for each part of the feature (14). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| Document.parseHTML_static | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Element.setHTML | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer.Sanitizer | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer.allowAttribute | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer.allowElement | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer.get | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer.removeAttribute | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer.removeElement | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer.removeUnsafe | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer.replaceElementWithChildren | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer.setComments | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| Sanitizer.setDataAttributes | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |
| ShadowRoot.setHTML | 146 | 146 | 148 | ✕ | 146 | 148 | ✕ |