Minify HTML Online – Free Safe HTML Minifier
Smaller HTML, same page.
At a glance
- Input:
- HTML
- Processing:
- Runs locally in your browser
- Privacy:
- Nothing you type is sent to a server
Last updated: 2026-11-14
Common use cases
- Shrinking an HTML file before deploying it to production
- Cleaning up a pasted snippet from a tutorial or a Stack Overflow answer
- Checking what minification actually removes, rule by rule, before trusting it
- Keeping a conditional comment for old browsers while everything else gets minified
About this tool
A fast, private HTML minifier that strips comments and whitespace without ever breaking a page — a hand-written tokenizer with no dependencies, proven safe on a 79-case corpus: protected regions stay byte-identical, spaces between inline elements are kept, and only whitespace CSS drops anyway is removed.
How to use it
- Paste HTML into the editor.
- Pick a level — Safe, Standard or Aggressive (⌘/Ctrl+Enter works too).
- Choose whether <!--! important comments stay or go.
- Copy the result or download as .html.
Worked examples
Input: <!-- Page header --> <div class="wrap"> <h1>Hello</h1> <!-- TODO: tidy this --> <p>Welcome to my site.</p> </div>
Output: <div class=wrap><h1>Hello</h1><p>Welcome to my site.</p></div>
119 characters → 62 characters = 47.9% smaller — both comments and all indentation gone, the page renders exactly the same.
Input: <pre> keep this exactly</pre> <p> normal text </p>
Output: <pre> keep this exactly</pre><p>normal text</p>
The <pre> block is byte-identical — spaces and the line break inside it are untouched — while the <p> collapses to 'normal text'. 59 characters → 52 characters = 11.9% smaller.
Input: <div> <p>Hello <em>world</em>!</p> <p>Buy <strong>now</strong>, pay later.</p> </div>
Output: <div><p>Hello <em>world</em>!</p><p>Buy <strong>now</strong>, pay later.</p></div>
The spaces before <em> and <strong> are KEPT — they render — while the indentation and line breaks around the block elements go. 89 characters → 82 characters = 7.9% smaller.
Practical tips
- Use Ctrl/⌘+Enter to re-run after each paste — the shortcut keeps hands on the keyboard.
- Start on Safe for a page you have never minified, then try Standard — the savings difference is usually small.
- Keep <!--! ... --> on if your page carries a license header — it survives minification.
- Minify a copy, not your only copy: keep the readable source and ship the minified file.
Common mistakes
- Minifying before checking the page renders: read the formatted version first, minify only when size matters.
- Pasting HTML with an unclosed comment — the error names the exact line and column of the opening <!--.
- Expecting minification to fix broken HTML: it only shrinks valid markup, it never repairs it.
- Pasting JSX or a template with ${...} placeholders — this tool handles plain HTML only; strip framework syntax first.
How this compares
Most HTML minifiers in the field are server-side paste bins that upload your markup, or thin wrappers that strip whitespace blindly — including the space between two inline elements, which changes rendering. This one minifies locally with no upload, protects pre, script, style and textarea byte-for-byte, and keeps every space that renders — proven on a 79-case corpus. The tradeoff: no identifier mangling (HTML has none to mangle) and no formatting/beautifying mode — the output is smaller, not prettier; for readable markup, pair it with the HTML formatter.
Good to know
- Safe minify only — the savings come from comments and whitespace alone (typically 10–30% on hand-written pages; already-compact pages save ~10%).
- Plain HTML only — JSX, template syntax and framework placeholders are not supported.
- CSS display is invisible to the minifier: an element restyled with display: block or display: inline is still treated by its tag name — check the result on heavily restyled pages.
- The 1,000,000-character cap keeps huge pages responsive; split larger files before pasting.
Frequently asked questions
Does minifying send my HTML anywhere?
No. Minification runs entirely in your browser — safe even for pages with internal hostnames, API keys or tokens in comments you'd rather not leak.
What exactly does it change?
Only comments and whitespace — plus, on Standard, safe attribute shortening. The sample on this page goes from 338 to 245 characters — 27.5% smaller — with the page rendering exactly the same. Safe mode is the most conservative: it only removes whitespace CSS drops anyway.
Is it safe for <pre>, <script>, <style> and <textarea>?
Yes. Their content is copied byte-for-byte — indentation inside <pre>, JavaScript comparisons like a < b inside <script>, and CSS selectors like a > b inside <style> all survive untouched. The same goes for elements with xml:space="preserve" or white-space: pre.
Will it join words together or remove spaces I need?
No. A space between two inline elements renders, so it stays: 'Hello <em>world</em>!' keeps its space. Only whitespace next to block elements — where CSS drops it anyway — is removed, and text runs collapse to a single space.
What do the three levels do?
Safe removes comments and block-boundary whitespace only. Standard also collapses text whitespace and shortens attributes (checked="checked" becomes checked, class="box" becomes class=box). Aggressive also drops optional end tags (</p> before <p>) and default values (type="text/javascript"). Aggressive never touches content — only markup the HTML spec says is optional.
How large can input be, and what is not supported?
Up to 1,000,000 characters. It does not validate HTML or fix broken markup, and it cannot see CSS: an element restyled with display: block or display: inline is still treated by its tag name, so check the result on pages with heavy display restyling. Unclosed comments and unterminated attribute quotes are reported with the exact line and column instead of producing a broken file.

