HTML Minifier
Minify HTML: remove comments and collapse whitespace, optionally between tags too, and minify inline CSS. Content of pre, textarea and script stays untouched.
Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.
How to use the HTML Minifier
- 1 Paste your HTML.
- 2 Choose whether to remove comments, whitespace between tags and to minify inline CSS.
- 3 Copy the minified HTML; the size saving is shown below it.
About the HTML Minifier
HTML for people is full of indentation, line breaks and comments that browsers don't need. Minifying removes them, which makes pages, e-mail templates and embedded snippets smaller and slightly faster to download and parse.
By default the minifier removes comments (except Internet Explorer conditional comments), collapses every run of spaces, tabs and line breaks to one space, and minifies the CSS in <style> blocks with CSSO. The contents of <pre>, <textarea> and <script> are kept exactly, because whitespace and line breaks matter there.
"Remove whitespace between tags" saves a little more but can change the layout: between inline elements, such as two links or buttons next to each other, a space is visible. Check the result in a browser before using it. For real sites, combine minification with gzip or Brotli on the server for the biggest gain.
Frequently asked questions
Will minifying break my page?
With the default settings the rendered page looks the same. Removing whitespace between tags can join inline elements that were separated by a space.
Are inline scripts minified?
No, scripts are kept as they are to avoid breaking them. Use the JavaScript minifier for scripts, and include the result in your page.
How much does it save?
Typically 10–25% for handwritten HTML, more for heavily indented templates with comments. Gzip compression on top saves far more.
Why keep conditional comments?
Comments like <!--[if IE]> contain code that some (old) e-mail clients and browsers still execute, so removing them could change the result.