Skip to content

HTML Minifier

HTML Minifier strips whitespace and comments from your HTML to reduce file size and improve page load speed. Paste any snippet or full document, choose your options and get compressed output instantly, with the size saved. No build tools or npm packages required.

HTML

Content inside <pre>, <textarea>, <script> and <style> is always kept byte for byte.

Options

Runs of spaces become one; whitespace next to block tags goes. Spaces between inline elements stay.

Valid HTML, but some templating tools and XML parsers expect quotes. Off by default.

Original
685 B
Output
549 B
Saved
19.9%
136 B smaller
Minified HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Sample page</title><!--[if lt IE 9]><script src="html5shiv.js"></script><![endif]--><style>
      .card { padding: 1rem; }
    </style></head><body><div class="card" id="intro"><h1>Hello, world</h1><p>This paragraph has extra spaces and <strong>bold</strong> <em>words</em>.</p><pre>
  Preformatted text
      keeps its spacing
      </pre><button type="button" disabled="disabled">Save</button></div></body></html>

How to use

  1. Paste your HTML into the input box.
  2. Choose the options: collapse whitespace, remove comments (optionally keeping IE conditional comments), collapse boolean attributes and remove attribute quotes where safe.
  3. Check the minified output and the size saved; both update as you type.
  4. Copy the minified HTML or download it as an .html file.

Why use this tool?

Minifying HTML in the browser saves you from setting up Webpack, Gulp or PostHTML just to compress a single file or template snippet. This tool handles the optimizations that matter most, whitespace collapse and comment removal, and leaves anything whitespace-sensitive alone.

Frequently asked questions

What is the HTML Minifier?

A browser-based tool that removes unnecessary whitespace and comments from HTML, reducing file size without changing how the page renders or behaves.

Will minifying HTML break my JavaScript or inline event handlers?

No. Content inside <script>, <style>, <pre> and <textarea> is kept byte for byte, and inline event handlers like onclick are preserved exactly as written. Whitespace is only removed next to block-level tags; a single space between inline elements such as links and bold text is kept, so text doesn't run together.

Is it free?

Yes, the HTML Minifier is free with no signup required. It runs entirely in your browser, so nothing you paste is uploaded. Built by the Canvas Builder team.

Stop tweaking snippets. Build the whole site

This tool fixes one piece. Canvas Builder builds the entire page from a single prompt: sections, copy, styling, and responsive layout. You own the code.