# Sanitizing untrusted HTML

DevFeed: [Sanitizing untrusted HTML](<https://devfeed.tech/articles/sanitizing-untrusted-html-129400.md>)

Original publisher: [Read original article](<https://specification.website/spec/security/sanitizer-api/>)

Author: Joost de Valk

Published: 2026-11-11T00:00:00Z

Content type: tutorial

Language: en

Sources: [The Website Specification](<https://devfeed.tech/sources/the-website-specification.md>)

Topics: [HTML](<https://devfeed.tech/topics/html.md>), [Front end](<https://devfeed.tech/topics/frontend.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>)

Tags: [agent](<https://devfeed.tech/tags/agent.md>), [api](<https://devfeed.tech/tags/api.md>), [automatically](<https://devfeed.tech/tags/automatically.md>), [browser](<https://devfeed.tech/tags/browser.md>), [call-graph](<https://devfeed.tech/tags/call-graph.md>), [cms](<https://devfeed.tech/tags/cms.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [content](<https://devfeed.tech/tags/content.md>), [context](<https://devfeed.tech/tags/context.md>), [cross-site-scripting](<https://devfeed.tech/tags/cross-site-scripting.md>), [csp](<https://devfeed.tech/tags/csp.md>), [custom](<https://devfeed.tech/tags/custom.md>), [formatting](<https://devfeed.tech/tags/formatting.md>), [highlighting](<https://devfeed.tech/tags/highlighting.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [html](<https://devfeed.tech/tags/html.md>), [implement](<https://devfeed.tech/tags/implement.md>), [library](<https://devfeed.tech/tags/library.md>), [native](<https://devfeed.tech/tags/native.md>), [recommended](<https://devfeed.tech/tags/recommended.md>), [sanitizer](<https://devfeed.tech/tags/sanitizer.md>), [security](<https://devfeed.tech/tags/security.md>)

## AI overview

Sanitize untrusted HTML at each insertion point so legitimate formatting can render while executable or hostile markup is removed. Where available, the native `setHTML()` API sanitizes and inserts using a default configuration; an explicit `Sanitizer` allowlist can preserve needed elements or attributes. The excerpt says the API shipped in Firefox 148 and Chrome/Edge 146 in early 2026, but not Safari, so it recommends maintained DOMPurify elsewhere, loaded from your own origin or with Subresource Integrity from a CDN. With Trusted Types, a helper can return `TrustedHTML` only after sanitization, though `setHTML()` itself bypasses Trusted Types. The excerpt also recommends server-side sanitization for other rendering contexts, reviewing configuration changes, and testing XSS and mutation-XSS payloads. HTML sanitization does not make values safe for other contexts such as `href` or JSON-LD.

## Source excerpt

Any HTML you did not author must be sanitized before it reaches the DOM: with the native Sanitizer API (setHTML and explicit Sanitizer configurations) where available, and a maintained library such as DOMPurify everywhere else.