The HTML Sanitizer API

Title “The HTML Sanitizer API” by Ahmad Alfy, over overlapping code snippets with DOMPurify imports and a new Sanitizer(config) example.

Ahmad Alfy walks through the new browser-native API that prevents XSS without DOMPurify. Safe methods setHTML and parseHTML always strip dangerous content, while setHTMLUnsafe and parseHTMLUnsafe respect your configuration. Allow-lists and block-lists give fine-grained control over elements and attributes. Great for comment sections, WYSIWYG editors, and markdown previews, though backend sanitization stays essential.

alfy.blog/2026/05/07/html-sanitizer-api.html