HTML Cleaner: Online HTML Sanitizer
Clean and sanitize messy HTML. Removes inline styles, event handlers, script tags, empty elements, and normalizes whitespace: all in your browser.
Messy HTML
Clean HTML
What Is an HTML Cleaner?
Copy HTML out of a Word document, a WYSIWYG editor, or an old CMS and you'll usually get a mess: inline styles on every element, empty spans and divs, onclick handlers, tracking scripts, and redundant attributes everywhere. An HTML cleaner strips that out and hands you clean, readable markup. This tool uses the browser's own DOMParser API to parse the HTML, then applies a series of cleanup passes: removing <script> and <style> tags, stripping inline styles, removing event handlers (onclick, onload, etc.), and deleting empty elements.
Whatever survives is re-indented, and only the contents of <body> come back, so the <head> with its title and meta tags is gone. The parsing is done by the browser's own DOMParser in this tab. Treat the result as tidier, not as safe: a href="javascript:..." link is left exactly as it was, so for HTML that comes from users, run it through DOMPurify as well. To confirm the stripped markup still holds together, paste it into the W3C HTML validator, and the Google HTML/CSS Style Guide has sensible rules for keeping it that way.
How to Use This Tool
Paste your messy HTML
Paste any HTML into the left editor: from a CMS, email editor, or template file. Click Sample to see a before/after with real messy markup.
Read the cleaned HTML
The right panel shows the cleaned result in real time. Scripts, inline styles, event handlers, and empty tags are removed. The output is reformatted for readability.
Copy or download the result
Use Copy to grab the cleaned HTML or Download to save it. To convert the cleaned HTML to React JSX, try the HTML to JSX tool next.
Cleaning Example
Paste this into the tool and see how it gets cleaned up. Inline styles, scripts, event handlers, and empty tags all get stripped:
Before cleaning
When You Actually Need This
The most common scenario is pasting HTML from a rich text editor (like TinyMCE, Quill, or a CMS WYSIWYG field) into a codebase. Those editors generate inline styles and empty tags by the dozen. It's also useful when working with HTML exported from Microsoft Word or LibreOffice, which notoriously generates excessive markup. The OWASP XSS prevention guide explains why removing event handlers and scripts matters from a security perspective. The Tidy HTML5 project is a CLI tool for similar cleanup tasks if you need to automate this in a build pipeline.
To validate the cleaned HTML structure, use the HTML Validator tool.
Frequently Asked Questions
What exactly gets removed?
The cleaner removes: <script> and <style> tags, all style="..." attributes, all event handler attributes (onclick, onload, onmouseover, etc.), and empty elements (not void elements like br or img, and not table cells, textarea, option or iframe, which are often empty on purpose).
Is this safe to use for untrusted HTML?
It removes the most common attack vectors (scripts, event handlers), but for production security you should use a dedicated library like DOMPurify which has been audited for security.
Does it preserve the structure and content?
Yes. Text content and structural elements (div, p, h1–h6, ul, table, etc.) are preserved. Only styling, scripting, and empty noise is removed.
Is my HTML sent to a server?
No. The cleaning uses the browser's DOMParser API entirely client-side. No data leaves your browser.
What about CSS classes: are those removed?
No. class attributes are preserved. Only style="..." inline styles are stripped. If you want to remove classes too, that would be a separate step.
Related Tools
DOMPurify is the gold standard for HTML sanitization in production. The MDN DOMParser documentation explains the browser API used under the hood.