b2KIT

HTML Sanitizer Tester

Test HTML sanitization by comparing raw input against DOMPurify and browser-native sanitization output.

Tested tool guide Tested browser tools Checked August 16, 2026

What HTML Sanitizer Tester does and how it behaves

Paste an HTML fragment to examine three distinct views: the source as entered, the markup accepted by DOMPurify, and the markup accepted by the browser's native sanitization facility. The comparison reveals removed elements, stripped attributes, and parser-driven normalization that can be difficult to notice during source review. The common mistake is treating unchanged or matching output as a universal safety verdict. The result describes only this fragment under these two sanitizers in the current browser; the eventual insertion context and later DOM changes still matter.

How the result is produced

1

Independent sanitizer results

Raw input is the baseline. DOMPurify and the browser-native facility receive the same fragment as separate tests, so a tag or attribute that survives in only one sanitized result exposes a concrete policy difference. Inspect the returned markup, not only what it would look like when rendered, because event-handler and URL-bearing attributes can be visually silent.

2

Parsing and serialization

Sanitization operates on parsed HTML structure, while the displayed result is serialized markup. HTML parsing can normalize quoting, casing, nesting, or omitted structure, so not every textual change represents removal of a security-sensitive feature. DOMPurify and the native sanitizer also need not share identical acceptance rules; equality on one fragment does not establish general equivalence.

Good uses

  • Check whether an inline event handler, script element, or suspicious URL survives either sanitizer before selecting a path for user-authored HTML.
  • Reduce an XSS regression report to a small HTML fragment and record how DOMPurify and native sanitization each rewrite it.
  • Compare mixed HTML and SVG markup when evaluating a migration from DOMPurify to browser-native sanitization.

Limits and checks

  • The result covers only the exact fragment tested. A minor change in nesting, namespace, attribute spelling, or surrounding markup can produce a different sanitized result.
  • Browser-native output can vary with browser support and release. A result obtained in one browser is not evidence that every supported browser will return identical markup.
  • Sanitized HTML is not automatically safe for JavaScript, CSS, URL, or attribute contexts. Later string concatenation, DOM mutation, or insertion into a different sink can invalidate the conclusion.

Common questions

If both sanitized outputs match, are DOMPurify and native sanitization equivalent?

No. Matching output proves only that both produced the same serialized result for that particular fragment under the conditions of the test. They may differ for other elements, attributes, namespaces, malformed markup, or browser versions. Test representative cases individually rather than treating one match as proof that the sanitizers have interchangeable policies.

Does removal of a script element prove the remaining HTML is safe to render?

No. Script removal is one useful observation, but active behavior can involve event attributes, unsafe URLs, embedded content, namespaced markup, or later DOM changes. Review the complete sanitized result and test it in the same kind of DOM sink used by the application. This tester compares transformations; it does not certify an entire rendering workflow.

References and verification

The behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools