HTML Minifier
Paste HTML and compress it as you type. The minifier deletes comments and collapses insignificant whitespace, including the gaps between tags, while leaving the contents of pre, textarea, script and style elements exactly as written. A badge reports the original and minified byte sizes and the percent saved, and you can copy the result or download it as minified.html.
How to minify HTML
- Paste or type your HTML into the HTML box, or click Load sample to try it.
- Watch the Minified box update instantly below the input.
- Check the badge above the output for the original size, minified size and percent saved.
- Copy the result with the Copy button, or save it with the download button as minified.html.
Examples
Strip a comment and collapse whitespace
<!-- nav --> <div class="box"> <p>Hello world</p> </div>
<div class="box"><p>Hello world</p></div>
Preserve whitespace inside pre
<div> <pre>a b</pre> </div>
<div> <pre>a b</pre> </div>
Keep an IE conditional comment, drop a normal one
<div><!--[if IE]>legacy<![endif]--><!-- normal --></div>
<div><!--[if IE]>legacy<![endif]--></div>
Frequently asked questions
Is my HTML sent to a server?
No. Minification runs entirely in your browser, so your markup never leaves your device.
How does HTML minification reduce file size?
It deletes comments and collapses repeated spaces, tabs and line breaks, including the whitespace that sits purely between two tags, so the same page ships in fewer bytes.
Will it break my inline scripts, styles or preformatted text?
No. Content inside pre, textarea, script and style tags is passed through exactly, so code, CSS and whitespace-sensitive blocks stay intact even though the surrounding markup is compressed.
Does it also minify the CSS or JavaScript inside those tags?
No. Because script and style contents are preserved verbatim, their whitespace and comments are left alone. Run a dedicated CSS or JavaScript minifier on those blocks if you want them compressed too.
Are IE conditional comments kept?
Yes. Conditional comments such as an if lt IE 9 block are load-bearing, so any comment containing an [if condition or an endif marker is detected and left in place while ordinary comments are removed.
Can collapsing whitespace ever change how the page renders?
Usually not, but there is one edge case. Whitespace between two tags is removed entirely, and a run of whitespace elsewhere becomes a single space. For inline elements like span or img, the difference between a single space and no space can shift spacing slightly, so review inline-sensitive layouts after minifying.
How is the percent saved calculated?
It compares the UTF-8 byte length of your input against the minified output, then reports the reduction as a percentage rounded to one decimal place. Multi-byte characters therefore count by their true byte size, not by character count.
Does it remove optional closing tags, quotes or shorten attributes?
No. The minifier only removes comments and insignificant whitespace. It never drops closing tags, unquotes attributes or rewrites your markup structure, so the output stays a faithful, well-formed version of the input.
Should I still gzip if I already minify?
Yes. Minification and gzip or brotli compression are complementary. Gzip does the heavy lifting on repeated strings during transfer, while minification removes bytes the compressor cannot recover, and together they beat either one alone.
Learn more
- HTML minification: what it removes and what it keeps
How collapsing whitespace and stripping comments shrinks HTML, why script, style and pre are preserved, and when to reach for gzip instead.
Related tools
HTML Entity Encoder
Encode text to HTML entities online. Escape &, <, >, " and ' so markup renders safely, with an option to convert non-ASCII characters too. Free and private.
JSON Formatter
Format, validate and minify JSON online. Pretty-print with custom indentation, sort keys and catch syntax errors. Runs in your browser.
HTML to JSX
Convert HTML to JSX for React. Rename class and for, camelCase attributes and events, turn inline styles into objects and self-close void tags.
Markdown to HTML
Convert Markdown to clean HTML in your browser. Headings, bold, italic, links, images, lists, blockquotes and fenced code blocks, with text safely escaped.
.env to JSON
Convert a .env file to JSON, or JSON back to .env. Parses KEY=value lines, comments, quotes and export. Runs entirely in your browser.
ASCII Table
Full ASCII table for all 128 codes with decimal, hex, octal and binary values, character names and descriptions. Search by code, hex or character.