b2KIT

HTML Sanitizer Tester

Test HTML sanitization with DOMPurify and configurable allow lists for tags, attributes, and URLs.

Tested tool guide Tested browser tools Checked August 16, 2026

What HTML Sanitizer Tester does, with a checked example

Paste an HTML fragment to see the markup DOMPurify returns after removing elements, attributes, and URL values that the selected allow lists do not permit. The controls let you test a policy for accepted tags, accepted attributes, and URLs instead of judging the original source by appearance alone. A common surprise is that permitting an element does not automatically permit every attribute or link value on it. Processing occurs in the browser, so potentially sensitive test markup is not uploaded.

Worked example

A concrete input and expected output from the current implementation.

Input

<p>Hello</p><script>alert(1)</script>

Expected output

<p>Hello</p>

Under DOMPurify's default sanitization policy, the paragraph is retained and the script element, including its JavaScript content, is removed. The surviving HTML therefore contains only the paragraph.

How the result is produced

1

Sanitize parsed HTML

DOMPurify evaluates the fragment as browser-parsed HTML and produces a cleaned fragment. Disallowed elements and unsafe attributes such as inline event handlers can be removed from the result. Because HTML parsing can repair malformed input or rearrange invalid nesting, the sanitized serialization may differ from the pasted source even when no obvious executable payload remains.

2

Apply separate allow lists

Tag, attribute, and URL permissions are separate parts of the test policy. An allowed anchor element, for example, does not imply that every attribute or every href value will survive. Adjusting one list can therefore change only part of an element. Review the returned markup to determine what DOMPurify retained under the exact settings being tested.

Good uses

  • Check whether an HTML snippet containing script elements, event-handler attributes, or suspicious links is reduced to the expected safe subset.
  • Develop a restricted rich-text policy by comparing which formatting tags and attributes remain under different allow-list choices.
  • Create regression examples for user-generated HTML before reproducing the same DOMPurify version and configuration in an application.

Limits and checks

  • A clean result covers only the fragment, DOMPurify version, and configuration tested. It is not proof that a different production configuration or later transformation will remain safe.
  • Sanitized HTML is intended for an HTML insertion context. It should not be treated as safe JavaScript, CSS, JSON, or as an unquoted attribute value.
  • A rendered preview can hide important removals and parser repairs. Inspect the returned source, especially attributes and URL-bearing elements, rather than relying only on visual similarity.

Common questions

Does allowing a tag preserve all of its attributes?

No. Element names and attribute names are evaluated separately, and URL-valued attributes can face additional restrictions. An allowed a element may remain while an event handler or unacceptable href is removed. Include every relevant policy control when testing, then inspect the serialized result instead of assuming that preservation of the outer tag means preservation of the original element.

Does unchanged output prove the HTML is safe everywhere?

No. It shows that this DOMPurify configuration did not alter that fragment. Safety still depends on where the result is inserted and whether application code later modifies it. Avoid passing sanitized markup into script, style, or other non-HTML contexts, and do not append unsanitized strings after sanitization.

References and verification

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

Related Tools