About this HTML compressor
Indentation, comments, and line breaks make HTML easy to edit, but visitors download every one of those characters. This compressor removes them safely. It drops comments while keeping old Internet Explorer conditional comments, turns runs of spaces and tabs into a single space, and removes line breaks between block elements. Between inline elements such as links and spans one space is kept, because removing it would join words on the page. Anything inside pre and textarea, and the code inside script and style, is copied exactly, so preformatted text and scripts keep working.
How to compress HTML
- Add your HTML. Paste markup, press Open an HTML file, or press an example.
- Choose what to remove. Keep Remove comments, Collapse whitespace, and Remove line breaks ticked for the smallest result, or untick any of them.
- Press Compress HTML. The compressed markup appears with the percentage saved and the characters before and after.
- Copy or download. Press Copy HTML, or Download to save it as page.min.html.
Frequently asked questions
Can compressing HTML break my page?
Not with these settings. Browsers already treat runs of whitespace as one space, and whitespace that could matter, inside pre, textarea, script, and style, is left alone. Between inline elements a single space is always kept.
Why are some comments kept?
Conditional comments such as <!--[if IE]> change what old versions of Internet Explorer load, so removing them could change the page. All other comments are removed.
What does collapse whitespace change in tags?
Extra spaces inside tags are removed and every attribute value is written in double quotes, so <div class=a> becomes <div class="a">. Untick it to copy every tag exactly as written.
Do I still need gzip on my server?
Yes. Compression on the server, such as gzip or Brotli, shrinks the transfer much more than minifying alone, and the two work well together. Minifying helps most with large pages and inline markup.