HTML Minifier

Paste HTML and get a smaller version in one click — comments removed and whitespace collapsed, while the content inside pre, script, style and textarea blocks is left exactly as it is.

Runs in your browser — your code and data never leave this device

How do I minify HTML online for free?

Paste your HTML here: this free online HTML minifier strips comments and collapses whitespace to shrink the file, while pre, script, style and textarea blocks stay protected — and the before and after sizes show exactly how much smaller it got. Copy the result or download it, with nothing uploaded.

Size: 0 B → 0 B
Input characters: 0

Related tools

How to use the HTML Minifier

  1. Paste your HTML into the Input box on the left, or click Sample to load an example page.
  2. Click Minify HTML. Comments are removed and the whitespace between tags is collapsed; pre, script, style and textarea blocks are protected and copied through unchanged.
  3. Check the size readout to see how many bytes were saved, then click Copy output or Download to save the minified page.
  4. Open the result in a browser to confirm it renders as expected before you publish it.

For the full picture — what minification touches, and the inline-spacing trap — read our guide: How to Minify HTML.

What gets removed, and what is protected

Minifying HTML removes the parts a browser ignores: comments, the line breaks and indentation between tags, and runs of several spaces collapsed into one. A page written with generous formatting can lose a third of its size without changing a single visible thing. The structure, the tags, the attributes and all of the text stay exactly where they were.

Four kinds of content are protected and copied through unchanged: pre blocks, where spacing is the content; script blocks, where a removed line break can change JavaScript; style blocks, where the same is true for CSS; and textarea blocks, where the text is user-facing. Everything else is fair game for whitespace removal.

Why minify HTML at all?

HTML is usually the smallest part of a page — images and scripts weigh far more — so minifying it saves less than minifying CSS or JavaScript. It still helps: the HTML document is the first thing a browser downloads, and a smaller document means the parser reaches the content sooner. On a site serving millions of pages, the bandwidth saving alone pays for the effort.

In practice, HTML minification usually happens in a build step or at the server, automatically, on every deploy. This page is for the one-off jobs: a landing page you built by hand, an email template, a snippet for a CMS, or a page you want to check quickly before pasting it somewhere that charges by the byte.

Servers can do this job for you, too. Some hosts and content delivery networks offer automatic HTML minification as a toggle — Cloudflare calls it Auto Minify, and web servers like Nginx can be configured to strip whitespace on the fly. That approach minifies every page without touching your source files, which is the best of both worlds when it is available. The tradeoff is control: server-side minification applies one policy to every page, while doing it by hand lets you check each page before it goes out.

When minifying can change how a page looks

Whitespace in HTML is mostly ignored, but not always. A single space between two inline elements — two words, two links, an icon and its label — is real content, and removing it would join them together. This tool is careful here: it only removes whitespace that contains a line break, which is the formatting between tags on separate lines. A single space between inline elements on the same line is kept.

Even so, check the result before publishing. Pages that rely on line breaks inside inline content, or on whitespace inside elements styled with white-space: pre-line, can shift slightly. The safe habit is the same as with any minifier: keep the readable original, minify a copy, and preview the copy in a browser.

Smaller pages, protected code blocks: what minifying does

Minify HTML online free and the saving comes from what browsers never needed: comments are removed, runs of whitespace collapse, and the file shrinks without changing how the page looks or behaves. The before and after sizes show the saving in bytes, so you can see the real difference for your page instead of a guess — and you can minify as often as you like, with no daily limit.

What it protects matters as much as what it removes: the contents of pre, script, style and textarea blocks are left untouched, because re-spacing code or preformatted text would change its meaning. One honest limit: the CSS and JavaScript inside the page are not minified — style and script blocks are copied through as they are, so minify those separately if they need shrinking too.

Frequently asked questions

Will minifying break my page?

Not for well-formed HTML. Comments and formatting whitespace are removed, while pre, script, style and textarea blocks are protected. Always preview the result before publishing, especially on pages that rely on spacing between inline elements.

Are HTML comments removed?

Yes, all comments are removed, including the ones developers leave as notes. If a comment carries a licence or attribution you need to keep, save it separately before minifying.

Does this tool minify the CSS and JavaScript inside my page?

No. Style and script blocks are copied through unchanged, so the CSS and JavaScript inside them are not minified. Use the CSS Minifier for stylesheets, and a JavaScript minifier for scripts.

Why is the saving smaller than I expected?

HTML is mostly tags and text, and tags cannot shrink. Pages with heavy indentation save the most. If your page is already written compactly, there is simply less whitespace to remove.

Is my HTML uploaded anywhere?

No. This tool runs entirely in your browser using JavaScript. Your code is never uploaded, stored or sent anywhere — everything stays on this device.

How much smaller will my HTML get?

It depends on how much whitespace and commenting the original has: a hand-written page with generous indentation shrinks more than an already-tight one. The tool shows the exact before and after sizes for your page, so you see the real saving, not a guess.

Can I minify HTML more than once a day?

Yes — there is no daily limit. The minifier runs entirely in your browser, so you can minify as many pages as you like, as often as you like, with no account and no waiting.

What is the difference between minifying and formatting HTML?

Minifying strips whitespace to shrink a file for production; formatting adds indentation so code is easy to read. They are opposites: minify when you want to ship a page, format when you want to read or edit it.