HTML Cleaner

Take the styling debris out of pasted HTML and get markup a CMS will accept without a fight.

Messy HTML
Clean HTML
Runs locally in your browser

About the HTML Cleaner

HTML copied out of a word processor, an email client or a page builder carries a payload nobody wants: style attributes with point sizes, MsoNormal classes, mso- properties, deprecated <font> wrappers, and empty paragraphs left where a page break used to be. This cleaner parses the markup, deletes that layer, and hands back indented HTML that inherits your own stylesheet instead of fighting it.

Each cleaning pass is a separate switch so you keep control. Inline styles also cover the old presentational attributes such as align, bgcolor, face, cellpadding and stray width values, though width and height stay on images and canvases where they prevent layout shift. Script removal takes out <script> elements, every on* handler and any javascript: URL, which makes it a sensible first step for markup you did not write. Empty element removal runs four passes so a hollow wrapper around a hollow wrapper disappears too, while cells, images, breaks and media elements are always kept.

The result is beautified with a two space indent so it reads well in a diff. If you would rather keep the styling and only shrink the file, use the HTML Minifier. To go all the way to unformatted prose, the HTML Tag Remover takes the tags off completely.

How to use

  1. Paste the HTML you copied, or drop an .html file on the left pane.
  2. Tick the passes you want. Remove class and id is off by default because those hooks are often deliberate.
  3. Check the cleaned markup on the right, then copy or download it.

Common questions

Does it remove the styling I actually want?
It removes style attributes on elements, not your stylesheet. Anything defined in an external CSS file still applies once the markup is back on your site.
Why are some empty elements still there?
Void and media elements such as img, br, hr, td, iframe, video and canvas are never treated as empty, because removing them would change the page.
Is this enough to make untrusted HTML safe?
It strips scripts, event handlers and javascript URLs, which covers the common cases, but it is not a security sanitiser. Server-side sanitisation is still required for user submitted content.
What happens to conditional comments for old Outlook?
They are ordinary comments to this parser and get removed with the comments pass. Untick that box when you are cleaning an email template.