๐๏ธ HTML Minifier
Strip comments and unnecessary whitespace/line breaks from HTML code to reduce its file size. Shows the byte size before and after, plus the percentage reduction, so you can see exactly how much lighter it got.
How to use
- Enter the HTML code you want to minify.
- The minified result appears automatically, along with the before/after size and reduction percentage.
- Use the "Copy" button to copy the minified result.
How the calculation works
This tool removes parts of the HTML that are not needed for display, making the file smaller. It works in three steps: 1. Remove comments (<!-- -->). 2. Remove whitespace and line breaks between tags (between ">" and "<"). 3. Collapse any remaining runs of two or more spaces into one. The saving is the difference between the original and minified sizes, counted in UTF-8 bytes. Japanese characters take three bytes each, so character count and byte count differ. If your server already serves HTML compressed with gzip or Brotli, whitespace compresses very efficiently in transit anyway, so the real reduction in transfer size is smaller than the percentage shown.
Worked example
Minifying this HTML <p> <b>Hello</b> <i>world</i> <!-- note --> </p> gives <p><b>Hello</b><i>world</i></p> The comment and line breaks are gone. But the space between <b>Hello</b> and <i>world</i> was removed too, so the page now displays "Helloworld" run together. Take care where spacing between inline elements matters.
Things to be aware of
- Spaces between inline elements (<b>, <a>, <span> and so on) are removed too, which can run words together.
- Whitespace and line breaks inside <pre> and <textarea> are collapsed as well.
- Code inside <script> and <style> is not optimised.
- Conditional comments (<!--[if IE]>) are removed along with ordinary ones.
FAQ
Does this collapse whitespace inside <pre> tags too?
This tool does simple whitespace collapsing, so meaningful whitespace inside a <pre> tag may get collapsed as well. Use caution with HTML that contains preformatted text.
Does this also minify the JavaScript or CSS code itself?
No โ code inside <script> or <style> tags isn't itself minified (no variable renaming, etc.). Only whitespace and comments between HTML tags are targeted.
Can I un-minify the result afterward?
Minifying itself has no built-in undo, but you can use our HTML Formatter to reformat it into readable code again.