HTML cleaner guide: source cleanup and sanitization
Use this HTML cleaner to remove selected markup, tidy pasted snippets or process a complete HTML document. Choose Source cleanup for controlled edits, or Sanitize HTML for a restricted HTML output profile. The result is displayed as code, not rendered as a page. Cleaning is not a substitute for checking the output in its destination.
How to clean HTML without losing the wrong content
Choose HTML fragment for a snippet or Full HTML document for a page, then select the cleaning mode and options. Click Clean HTML and inspect the result before copying. Changing input or options clears old output. Use result as input moves the current non-empty result back for another pass; it does not present the original uncleaned source as output. A successful result can be empty when every input node is removed.
Fragment mode versus full document mode
Fragment mode uses an inert template and returns its contents; html, head and body wrappers are not preserved as document wrappers. Select full document mode to parse a complete page and retain its doctype, html and body attributes, head and body structure in Source cleanup. The HTML parser can insert missing elements, repair invalid nesting, normalize line endings and change entity or attribute serialization. This is HTML processing, not XML validation or a lossless source editor.
Which removal options change the markup?
Remove script tags and Remove style tags delete those elements, including inside nested template contents. Strip inline styles removes only style attributes. Removing width, height and align is a separate option, off by default so image dimensions and table presentation are not deleted unintentionally. Comment removal also traverses templates. Source cleanup otherwise retains attributes and elements, including event handlers and embedded content; use sanitization when those must be removed. Script removal also deletes JSON-LD and other non-executable script data.
Whitespace, code samples and conservative formatting
Whitespace compression and block formatting are off by default. Compression changes ASCII whitespace only in ordinary text nodes; it never rewrites attribute values. Text in pre, code, textarea, script, style and other protected raw-text elements is kept, as are foreign namespaces and subtrees with an inline white-space declaration. Formatting indents only selected containers holding block elements; mixed text and adjacent inline elements keep their separators. Destination styles, including classes, can still make whitespace significant, so leave both options off when exact spacing matters.
<span>A</span><span>B</span>
<pre> first line
second line</pre>
What Sanitize HTML removes
Sanitization uses the locally hosted DOMPurify library with an HTML-only profile and additional restrictions. It always removes scripts, style elements, inline CSS, comments, embedded documents, form controls and document resource metadata such as meta, link and base elements. Event handlers and unsafe URL schemes are also filtered. These mandatory options are locked in the interface; switching back restores your Source cleanup choices. Safe output may therefore omit useful page metadata. For a complete trusted page, use full document Source cleanup and review its source carefully.
Local processing, browser behavior and limits
The cleaning function does not upload input or store it in browser storage, and the output is not inserted into the live page. Shared site resources still load. Full document mode uses DOMParser, which may request resources referenced by the input; neither mode is an offline or network isolation guarantee. Limits are 100,000 input UTF-16 units, 10,000 input nodes including template contents, 60 nesting levels and 1,000,000 output units. Processing occurs on the browser main thread with bounded input. Sanitization does not replace destination security checks or protect markup that is later modified unsafely.