coderef

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: 155
Edge
12–145Not supported
146+Supportedsince Mar 13, 2026
Current: 154
Firefox
1–147Not supported
148+Supportedsince Feb 24, 2026
Current: 157
Safari
✕Not supportedup to 27
Current: 27
MobileChrome Android
18–145Not supported
146+Supportedsince Mar 10, 2026
Current: 155
Firefox Android
4–147Not supported
148+Supportedsince Feb 24, 2026
Current: 157
Safari iOS
✕Not supportedup to 27
Current: 27

How 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-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Document.parseHTML_static146146148✕146148✕
Element.setHTML146146148✕146148✕
Sanitizer146146148✕146148✕
Sanitizer.Sanitizer146146148✕146148✕
Sanitizer.allowAttribute146146148✕146148✕
Sanitizer.allowElement146146148✕146148✕
Sanitizer.get146146148✕146148✕
Sanitizer.removeAttribute146146148✕146148✕
Sanitizer.removeElement146146148✕146148✕
Sanitizer.removeUnsafe146146148✕146148✕
Sanitizer.replaceElementWithChildren146146148✕146148✕
Sanitizer.setComments146146148✕146148✕
Sanitizer.setDataAttributes146146148✕146148✕
ShadowRoot.setHTML146146148✕146148✕