An HTML minifier takes a page full of indentation, line breaks and comments and writes the same page on far fewer bytes. Our free HTML Minifier does this in your browser, with three switches to decide how far it goes and a size panel that shows the saving before and after gzip. It suits developers who hand-write templates, people who export HTML from a page builder, and anyone preparing an email or landing page where every kilobyte counts.
This guide explains exactly what the tool changes, what it refuses to touch, and how to check the result. If you also want the stylesheet and script files smaller, the companion guides cover the CSS Minifier and the JS Minifier.
What HTML Minifier does
The tool is deliberately conservative. It reads your HTML as a stream of tags, text and comments, and then:
- Removes ordinary comments such as
<!-- Page styles -->. - Collapses runs of spaces, tabs and line breaks in text down to a single space, and removes that space completely where it sits next to a block element such as
<div>,<p>,<li>or<table>. - Tidies the inside of tags: several spaces between attributes become one, and spaces around
=disappear. - Optionally minifies the CSS inside
<style>blocks and the JavaScript inside<script>blocks.
It does not rename classes, merge files, reorder attributes, remove quotes from attribute values or drop optional end tags like </li>. It also does not check that your HTML is valid. If you have a stray tag, it will still be minified, and the problem stays in the output.
How to use HTML Minifier, step by step
- Open HTML Minifier.
- Paste your page into the box labelled "Paste HTML". You can also press Open file and choose an
.htmlor.htmfile, or press Sample to see how it behaves. - Choose the options above the panels: Remove comments, Collapse whitespace and Minify inline CSS & JS.
- Read the result in the right-hand panel, titled "Minified". It updates about 0.4 seconds after you stop typing, and a "Minifying…" label shows while it works.
- Check the numbers under the panels: Original, Minified, Saved, Gzip original, Gzip minified and Time.
- Press Copy to copy the result, or Download to save it. The file is named
index.min.html, with the site's "Tech Solution Point - " prefix in front.
Use Clear to empty the input and start again.
Every option explained
Remove comments (on by default)
Turns <!-- … --> comments into nothing. One kind of comment is always kept, even with this switched on: conditional comments such as <!--[if IE]> … <![endif]-->. They were used to target old versions of Internet Explorer and can contain real markup, so deleting them could change what a visitor sees. The doctype and CDATA sections are also kept.
Turn this option off if your comments carry meaning, for example a licence notice or a marker that another tool replaces later.
Collapse whitespace (on by default)
This is the option that saves the most bytes on hand-written HTML, because indentation is mostly spaces. It collapses runs of whitespace in text to one space and removes the space next to block elements, where browsers would not draw it anyway. It also cleans up inside tags, so <div class="card" id = "a" > becomes <div class="card" id="a">.
The tool treats a long list of tags as blocks (html, head, body, div, p, ul, li, table, tr, td, h1 to h6, form, section, br and others). Whitespace next to those is removed. Elements not on that list, such as <a>, <span>, <b>, <em>, <button> and <img>, are treated as inline, so a space between two of them survives as one space. That is why <b>bold</b> <i>italic</i> keeps its gap.
If you untick this option, text and tags are left exactly as written, and only the comment option still applies. One visible side effect: when a comment sits alone on its own indented line, removing it leaves a blank line behind, because the line break around it is kept.
Minify inline CSS & JS (off by default)
When ticked, the tool also compresses what is inside your <style> and <script> tags:
<style>blocks go through the same engine as the CSS Minifier, without the rule-merging step, and keep/*! … */comments.<script>blocks that are ordinary JavaScript ortype="module"go through the same engine as the JS Minifier, with name shortening and compression on.<script type="application/ld+json">,application/jsonandimportmapblocks are rewritten as compact JSON.- Anything else, such as
type="text/template", is left unchanged.
If a block cannot be parsed, it is left as it was and a yellow note appears, for example "Left an inline <script> block unchanged: Unexpected token: punc (()". The rest of the page is still minified.
A worked example
Press Sample and you get a small page with a comment, a style block, a conditional comment, a <pre> and a script. With the defaults, the result is:
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>My page</title><style>
body { margin: 0; font-family: system-ui, sans-serif; }
.card { padding: 16px; border-radius: 12px; }
</style></head><body><!--[if IE]><p>Please upgrade your browser.</p><![endif]--><div class="card" data-note="keep these spaces"><h1>Hello, <em>world</em>!</h1><p>Inline <b>bold</b> <i>italic</i> words keep their spaces.</p><pre>
preformatted
text stays as-is
</pre></div><script>
// greet the visitor
function greet(name) {
const message = "Hello, " + name + "!";
console.log(message);
}
greet("visitor");
</script></body></html>
The title lost its extra spaces, the <!-- Page styles --> comment is gone, and the <pre> block and the data-note value keep their spacing. The style and script are unchanged, because Minify inline CSS & JS is off. The size goes from 825 to 701 bytes, about 15% saved.
Now tick Minify inline CSS & JS. The style block becomes body{margin:0;font-family:system-ui,sans-serif}.card{padding:16px;border-radius:12px} and the script becomes function greet(o){const e="Hello, "+o+"!";console.log(e)}greet("visitor");. The page is now 569 bytes, about 31% smaller than the original.
What it accepts and its limits
- Input: any HTML text, a full page or just a fragment. You can paste it or open an
.htmlor.htmfile. - Live mode: up to 300,000 characters, the page minifies as you type and when you change an option.
- Large input: above 300,000 characters it stops minifying on every keystroke. A Minify button appears with the hint "Large input (…) — click Minify to run."
- Empty input: shows the message "Paste HTML or load the sample — it's minified in your browser as you type."
- Output: one text box with Copy and Download. Nothing is cut off.
Privacy
HTML Minifier runs in your browser. Your page, including any inline scripts, stays on your device and is not sent to our server. That makes it fine for unpublished pages and internal templates. As always, avoid leaving real passwords or API keys in a page you paste anywhere, because minifying does not remove them.
Reading the size numbers
The stats row compares the original and minified sizes in bytes, then the same two files compressed with gzip. Gzip numbers are the more honest ones for a website, because servers normally compress HTML before sending it. Gzip already squeezes repeated spaces well, so the gap between "Gzip original" and "Gzip minified" is usually much smaller than the gap between the raw sizes. If the gzip figures show "n/a", your browser does not support the compression feature the page uses; the other numbers still work.
Saved is the raw saving as a percentage. It is a good guide for places where nothing compresses the file, such as an email template or HTML pasted into a CMS field.
Tips to work faster
- Minify the final version only. Keep your readable source in your project, and treat the minified file as build output.
- Test the page in the browser after minifying, especially if you tick Minify inline CSS & JS.
- If a layout looks different, untick Collapse whitespace and compare. Differences are rare, but inline elements next to each other are where they would show.
- For an HTML email, use Remove comments and Collapse whitespace, and leave the inline option off if your email client strips scripts anyway.
- Do the stylesheet and script files separately with the CSS Minifier and JS Minifier if they live in their own files.
Common problems and how to fix them
"Left an inline <script> block unchanged"
The script inside your HTML has a syntax error, or uses something the engine cannot parse. The note includes the reason. Fix the script, or paste it into the JS Minifier, which shows the line and column of the error.
The page looks different after minifying
First untick Minify inline CSS & JS and check again. If the difference remains, untick Collapse whitespace. A space that matters should be kept, but pages that use white-space styles on ordinary elements can rely on spaces the tool cannot know about. Wrap that content in <pre> or <textarea>, whose contents are never touched.
A comment I wanted to keep disappeared
Only conditional comments are protected. Untick Remove comments to keep everything, or move the important text into a licence block in your CSS or JS where /*! … */ comments are kept.
The saving is small
That is normal. A page that is already compact, or mostly text, has little whitespace to remove. Heavily indented, heavily commented templates gain the most, and ticking Minify inline CSS & JS adds more if the page carries large style or script blocks.
Related tools
- CSS Minifier: shrink a stylesheet, shorten colours and merge repeated rules.
- JS Minifier: compress JavaScript and see syntax errors with line and column.
- Developer Tools: the rest of our developer utilities.
Quick checklist
- Keep Remove comments and Collapse whitespace on for normal pages.
- Tick Minify inline CSS & JS only if you will test the page afterwards.
- Read the gzip numbers, not just the raw saving.
- Keep your readable source and publish the minified copy.
- Download as
index.min.htmland rename it to fit your project.



