HTML Minifier
Make an HTML page smaller for faster loading, without changing how it looks. Text inside <pre> and <textarea> is left alone.
or drop a file here · .html, .htm, .txt · up to 20 MB
About the HTML Minifier
On a slow mobile connection, the indentation, comments and padded scripts of a hand-written page add up. This minifier strips what browsers ignore, while being careful about the spaces that do affect the layout.
When to use it
- You publish static pages or email templates without a build tool.
- A landing page scores poorly in a speed test because of its HTML size.
Worked example
Press Try an example, leave all three options ticked and choose Minify HTML. The output is a single line. The comment “page header” is gone, the head and body tags follow each other with no gaps, the attributes lang, charset and so on lose their quotes where that is safe, and the stylesheet shrinks to one compact rule with the colour #333333 shortened to #333. Inside the script, the greet function’s parameter is renamed to one letter. In the paragraph, the gap after the full stop is reduced to one space and the space before the bold word is kept.
What each option does
- Remove comments: deletes HTML comments, except Internet Explorer conditional comments.
- Remove spaces between block tags: drops whitespace next to elements such as div, p, li and table, where a browser would not display it. A single space between inline tags is always kept.
- Minify CSS and JavaScript inside the page: compresses style blocks with CSSO and classic or module scripts with Terser. JSON-LD and other data scripts are left untouched. If a script has a syntax error, it is copied unchanged and you see a warning.
Things that are never changed
- Text inside pre and textarea elements.
- Attribute values, apart from removing quotes that are not needed.
Good to know
- Keep your readable original; the HTML formatter can re-indent minified markup but cannot restore removed comments.
- For separate files, use the CSS minifier and the JavaScript minifier.
How to use HTML Minifier
- Paste HTML or open an .html file.
- Choose what to remove and whether to minify embedded CSS and JavaScript.
- Select Minify HTML, check the size saved, then copy or download the result.
Privacy: how it works
Everything happens in your browser. Your text is not sent to any server.
Frequently asked questions
Is it safe for my layout?
Runs of spaces are reduced to one space, and spaces are removed only next to block tags such as <div>, <p> and <li>, where browsers ignore them. A single space between inline tags such as <b> and <i> is kept.
What happens to my scripts?
With the embedded option on, JavaScript in <script> tags is minified with Terser. If a script cannot be read, it is copied unchanged and you get a warning. JSON-LD and other data scripts are never changed.
Are Internet Explorer conditional comments kept?
Yes. Comments starting with <!--[if are kept even when removing comments.