HTML Minifier

HTML Minifier — Minify HTML Online Free

HTML Minifier — Minify HTML Online Free

Paste your HTML below, pick a level, and get a smaller file in one click. This tool removes comments and extra whitespace, and at higher levels it trims more of the characters browsers do not need to display the page.

Email templates: Gmail clips messages over about 102 KB, so a long email can get cut off for the reader. Minifying email HTML is one simple way to keep a template under that limit.
Privacy: This tool runs locally in your browser. Your code is never uploaded to a server.

What Is an HTML Minifier?

An HTML minifier is a tool that makes an HTML file smaller by removing characters the browser does not need, such as comments and extra spaces and line breaks. The page still looks and works the same, because the tags, text, and links are left in place.

Smaller HTML loads faster and uses less data. That matters most for large pages, for pages served to many visitors, and for email templates, where size limits can cut a message short.

What Each Level Removes

LevelWhat it removesWhen to use it
Safe HTML comments, and whitespace between tags (line breaks and indentation that sit between one tag and the next). When you want the smallest risk. Text inside your page is left exactly as written.
Standard Everything in Safe, plus extra whitespace inside text nodes — repeated spaces become one space, and spaces at the start or end of a text block are trimmed. Whitespace inside <pre>, <textarea>, <script>, and <style> is never collapsed. For most pages. It saves more than Safe while keeping code blocks and scripts intact.
Maximum Everything in Standard, plus quotes around attribute values when the value is simple (letters, digits, and characters such as -, _, ., :), and a few optional closing tags where they can be left out safely, such as </li> before another list item. When you want the smallest file and you will test the result. Keep a copy of the original, and check the page in a browser before you publish.

Inline CSS and JavaScript are handled conservatively at every level: the contents of <script> and <style> blocks are never rewritten — only leading and trailing whitespace around them is trimmed. That keeps code such as if (x < 2) working, because the < inside a script is not mistaken for a tag.

Worked Example

Here is a small page, minified at each level with this very tool. The byte counts below are real results from running the tool on this input.

Before — 240 bytes

<!DOCTYPE html>
<html lang="en">
<head>
  <title>  My Page  </title>
  <!-- Page styles -->
  <style>
    body { margin: 0; }
  </style>
</head>
<body>
  <h1>   Hello, World!   </h1>
  <p> This is a    sample paragraph. </p>
</body>
</html>

After — Safe: 191 bytes (20.4% saved)

<!DOCTYPE html><html lang="en"><head><title>  My Page  </title><style>body { margin: 0; }</style></head><body><h1>   Hello, World!   </h1><p> This is a    sample paragraph. </p></body></html>

The comment is gone and the line breaks between tags are gone, but the spaces inside the title, heading, and paragraph are untouched.

After — Standard: 176 bytes (26.7% saved)

<!DOCTYPE html><html lang="en"><head><title>My Page</title><style>body { margin: 0; }</style></head><body><h1>Hello, World!</h1><p>This is a sample paragraph.</p></body></html>

Now the extra spaces inside the text are collapsed too, while the style block is left as it was.

After — Maximum: 174 bytes (27.5% saved)

<!DOCTYPE html><html lang=en><head><title>My Page</title><style>body { margin: 0; }</style></head><body><h1>Hello, World!</h1><p>This is a sample paragraph.</p></body></html>

The only extra saving here is the quotes around en in lang=en. On a small page the jump from Standard to Maximum is tiny; on a large page with many attributes it adds up.

How to Minify HTML Online

  1. Paste your HTML into the input box at the top of this page.
  2. Pick a level. Start with Safe if the page is important and you have not tested minified output before; use Standard for everyday pages.
  3. Click “Minify HTML”. The result appears in the output box, with the original size, the new size, and the percentage saved.
  4. Check the result. Open the minified file in a browser and confirm the page looks and works as before — especially any code samples, forms, and scripts.
  5. Copy or download it. Use the Copy button to paste it where you need it, or Download .html to save it as a file.
  6. Keep your original. Save the unminified file somewhere safe, so you can edit it later and minify again.

FAQ

Will minified HTML still look the same?

Yes, in normal cases. Minifying only removes characters that do not change how the browser renders the page — comments, extra whitespace, and, at Maximum, quotes and closing tags that are optional. The one place to be careful is content where spaces matter, such as text inside <pre> blocks. This tool never collapses whitespace inside <pre> or <textarea>, and you should still preview the result before publishing.

Is my code uploaded anywhere?

No. The minifier runs entirely in your browser with JavaScript on this page. Your HTML is never sent to a server, stored, or shared. You can even use the page offline once it has loaded.

Which level should I use?

Use Safe when you want the lowest risk, Standard for most pages, and Maximum when you want the smallest file and are willing to test the result. If you are unsure, start with Standard — it gives most of the saving with very little risk.

Does minifying break JavaScript or CSS?

It should not, with this tool. The contents of <script> and <style> blocks are not rewritten; only the whitespace around them is trimmed. JavaScript that contains characters such as < is therefore left alone. Even so, always test a minified page that contains scripts before you publish it.

Can I minify an email template?

Yes, and email is one of the best uses for it. Gmail clips messages over about 102 KB, so trimming comments and extra whitespace can keep a long template readable. Use Safe or Standard for email, and test the template in an email client before sending it to real readers.

Should I edit the minified file directly?

No. Edit your original, readable HTML and minify it again afterwards. A minified file is one long line and is hard to read or change by hand — that is the point of minifying, and also why you should keep the original.

Privacy note: Everything on this page runs locally in your browser. Nothing you paste is uploaded, stored, or sent anywhere.

Featured on LaunchNest