HTML Minifier
Remove HTML comments and collapse unnecessary whitespace.
Your result will appear here…
How to use HTML Minifier
- Paste your HTML.
- Select Minify.
- Compare the result in a browser before you use it.
Example
Input / settings:
<main> <!-- greeting --> <h1> Hello </h1> </main>
Output:
<main><h1> Hello </h1></main>
The comment and the whitespace between tags are removed. Spaces at the edges of text become one space.
When to use
- Compact a small HTML snippet or an email fragment.
- Remove build or author comments before sharing markup.
- Check how much of a template is whitespace.
Overview
HTML Minifier removes ordinary comments, collapses each run of whitespace in text to a single space, and drops whitespace-only text between tags. Tags and attributes are left exactly as written, and plain text inside script, style, pre and textarea elements is kept. It is a text tool, not a full HTML parser, and it does not shorten attributes or remove optional tags.
Supported input
HTML text
Output details
compact HTML
Common mistakes
- Whitespace between inline elements is deleted. <p><b>a</b> <i>b</i></p> becomes <p><b>a</b><i>b</i></p>, and a browser shows ab where it showed a b.
- The same happens inside pre. Plain text in <pre> is kept as written, but a space between two tags inside it is removed.
- Every comment is removed except those that start with <!--!. That includes conditional comments such as <!--[if IE]>…<![endif]-->.
- A < inside script text confuses tag detection. After <script>if (a < b) {}</script>, the rest of the document is no longer minified.
- Attributes are not tidied. <a href="x" class = "y" > keeps its spacing, and stays as written.
Practical tips
- Whitespace between inline elements is the usual cause of a layout change, so look at those first when the page looks different.
- For a whole site, run a minifier in your build pipeline; this tool is meant for snippets.
Privacy and security
This tool runs entirely in your browser. Your input is never uploaded to our servers. Minification runs locally and only removes comments and whitespace. It does not sanitize markup, so the output does whatever the input did. Removing comments can delete notes you wanted to keep, so check them first.
References
Frequently asked questions
Does HTML Minifier remove optional tags or shorten attributes?
No. Tags and attributes are written back as they were. Only comments and whitespace change.
Which comments does the minifier keep?
Comments that begin with <!--! are kept. All other comments are removed, including conditional comments.
Why did two words run together after minifying?
A space that sat alone between two tags was removed. Put the space inside one of the elements, or use .