How to minify HTML
Paste the code
Paste your page’s code or open an .html file, or try “Example”.
Choose what to minify
Comments, whitespace, and inline CSS and JavaScript, all on by default.
Copy or download
Press “Minify” to see the size before and after and the savings, then copy or download it.
What changes in the code?
| What we do | Example | Does the page look different? |
|---|---|---|
| Remove comments | <!-- ... --> | No. Licence comments starting with <!--! are kept. |
| Collapse whitespace | Several spaces and lines → one space | No. One space stays wherever there was whitespace, so words and elements never stick together. |
| Minify inline CSS | <style> and style="" | No. Only whitespace and comments go; rules keep their order. |
| Minify inline JavaScript | <script> and onclick="" | No. With the same Terser engine as our JavaScript Minifier. |
| Left untouched | <pre> and <textarea> | They stay exactly as you wrote them. |
Tips
Turn on server compression too. gzip or Brotli on your host shrinks transfers much more; minifying adds a small, steady saving on top.
Keep the original. Always edit the readable source and minify a copy for upload; minified code is hard to edit.
A script with an error? If an inline script has a syntax error, we leave it as it is and tell you; the rest of the page is still minified.
FAQ
Does minifying HTML change how the page looks?
No. One space stays wherever there was whitespace, so words and side-by-side buttons never stick together, and <pre> and <textarea> are left as they are. We tested it on dozens of real Arabic and English pages by comparing the page tree and its text before and after.
How much does HTML minification save?
It depends on the page: about 5% for tightly written pages, over 40% for pages with many comments and spaces or loosely formatted inline CSS and JavaScript.
Are inline CSS and JavaScript minified?
Yes: inside <style> and <script> and in style and onclick attributes. You can turn this off in the options. JSON-LD is compacted with its data unchanged.
Which library does it use?
html-minifier-next (MIT), the maintained successor of the well-known HTML Minifier, with Terser for JavaScript and our own CSS minifier that only removes whitespace and comments.
Can I use it on WordPress or PHP templates?
It leaves <?php ?> and <% %> blocks untouched, but it’s better to minify the rendered page, not the template, or use a caching plugin that does it for you.
