HTML Minifier
Paste HTML to strip comments and redundant whitespace and shrink the file, with pre, textarea, script and style content preserved — instantly in your browser.
Updated
How to use HTML Minifier
The HTML Minifier shrinks HTML documents by removing the bytes a browser does not need, instantly and entirely in your browser. It strips HTML comments, collapses runs of whitespace between and inside tags, and optionally removes empty attributes, all while carefully preserving the content of pre, textarea, script and style blocks where whitespace is significant. Smaller HTML downloads faster and parses a little quicker, which helps page-load metrics — and because everything runs client-side, you can paste templates or full pages without sending them to any server.
- Paste your HTML into the input area.
- Toggle which optimisations to apply (comments, whitespace, empty attributes).
- Read the minified HTML in the output area.
- Check the before and after byte counts.
- Copy the minified markup into your project.
Your data never leaves your device — 100% private processing.
What the minifier changes
Minification removes characters that have no effect on how the browser renders a page. The biggest wins usually come from collapsing whitespace: source HTML is often indented for readability, and those spaces, tabs and newlines between tags are insignificant in normal flow content. The minifier replaces each run with a single space, or removes it entirely between block-level tags. Comments are stripped unless they are conditional comments (the old <!--[if IE]> syntax), which some legacy targets still rely on. Empty attributes such as class="" or style="" can optionally be dropped because they carry no information. Crucially, none of this touches the inside of pre, textarea, script or style elements, where every space and newline can be meaningful — those regions are stashed before processing and restored afterwards untouched.
| Option | Effect |
|---|---|
| Remove comments | Deletes <!-- --> blocks (keeps conditional comments) |
| Collapse whitespace | Reduces runs of spaces/newlines to one space |
| Remove empty attributes | Drops class="", id="", style="" and similar |
| Preserve blocks | Leaves pre, textarea, script, style untouched |
Minification, gzip and real-world gains
It is fair to ask how much minification helps when servers already compress responses with gzip or brotli. Compression is very good at squeezing repetitive whitespace, so the saving from minified HTML after compression is smaller than the raw byte difference suggests — but it is rarely zero, because minification also removes comments and redundant structure that compression cannot infer away. More importantly, smaller HTML means less work for the browser to parse and less memory to hold the document, which matters on low-end devices. Treat HTML minification as one cheap optimisation among many: combine it with compression, caching and minified CSS and JavaScript rather than relying on any single technique. Because this tool is a quick paste-and-copy utility, it is ideal for one-off cleanups; for production sites, wire an equivalent step into your build pipeline so every deploy benefits automatically.
Worked examples
Strip comments
Inputs: <!-- nav --> <nav> … </nav>
Result: <nav> … </nav>
Collapse whitespace
Inputs: <p> hi </p>
Result: <p> hi </p>
Glossary
- Minification
- Removing characters that do not affect output to reduce file size.
- Whitespace collapsing
- Replacing runs of spaces, tabs and newlines with a single space.
- Conditional comment
- A legacy <!--[if IE]> comment that some old browsers interpret as markup.
- Significant whitespace
- Spaces and newlines that affect rendering, as inside a pre or textarea element.
- Empty attribute
- An attribute with no value, such as class="", that can be safely removed.
Related reading
Frequently Asked Questions
Get weekly tool tips & updates
New tools, power-user tips, and productivity hacks — delivered free every Friday.
No spam, ever. Unsubscribe with one click.
Why use HTML Minifier?
- Removes comments and collapses redundant whitespace
- Preserves pre, textarea, script and style content exactly
- Optional removal of empty class, id, style and similar attributes
- Reports the byte savings so you can see the impact
- Runs client-side — your markup never leaves the browser
Common use cases
- Trim template output before shipping a static page
- Reduce inline HTML size in emails or embedded snippets
- Clean up exported or generated markup before committing
- Compare original and minified size to justify a build step
- Quickly strip comments from a page before sharing it
Related Developer Tools
CSS Minifier & Beautifier
Minify and beautify CSS code online. Reduce CSS file size by removing whitespace and comments. Free online CSS minifier with instant results.
HTML Encoder / Decoder
Encode and decode HTML entities online. Escape <, >, &, and quote characters for safe HTML display. Free, instant, and private — runs in your browser.
HTML ↔ Markdown
Convert HTML to clean Markdown and Markdown to HTML. Paste content and switch formats with a live preview. Free, private, in-browser.
JSON Formatter & Validator
Format, validate, and minify JSON instantly. Includes syntax highlighting, error detection, and a collapsible tree view — free, private, in-browser.
Regex Tester
Test and debug regular expressions online. See live matches, capture groups, and replace output. Free, private, instant.
Base64 Encoder & Decoder
Encode text or files to Base64, or decode Base64 strings back to text. Fast, free, and runs entirely in your browser.
Explore all Developer Tools.