HTML minifier
Minify HTML by removing comments and collapsing whitespace, while keeping pre, textarea and inline spacing intact. CSS in style tags is minified too.
About HTML minifier
The HTML minifier shrinks markup by removing comments and collapsing runs of spaces, tabs and line breaks. Paste a page or template and the compact version appears straight away, with its character count in the status bar, ready to copy or download.
It is deliberately conservative. Content inside <pre> and <textarea> is left untouched, a single space is kept between inline elements and words so text does not run together, attribute values are not changed, and conditional comments are preserved. CSS inside <style> elements is minified with the site’s own CSS minifier.
How to use HTML minifier
- Paste HTML into the input box, or open or drop an .html file.
- Review the minified output; the status bar shows its length in characters.
- Copy the result or download it as an .html file.
Features
- Removes HTML comments, except conditional comments (<!--[if …]>) and comments that start with <!--!.
- Collapses whitespace to a single space, and removes it entirely next to block-level elements such as div, p and li.
- Leaves <pre> and <textarea> content and attribute values exactly as written.
- Minifies CSS inside <style> elements; <script> content is only trimmed, not minified.
- Removes extra whitespace between attributes inside tags.
Common uses
- Reducing the size of static HTML pages or email templates.
- Embedding an HTML snippet in JSON, a JavaScript string or a database field.
- Shrinking server-rendered fragments before caching them.
- Checking how much of a page’s size is whitespace and comments.
Tips
- To minify inline JavaScript as well, run the script through the JavaScript minifier separately and paste the result back into the <script> element.
Frequently asked questions
Can minifying HTML break my page?
This minifier avoids risky optimizations: it does not remove optional tags or attribute quotes, does not touch <pre> or <textarea>, and keeps one space between inline content. Whitespace next to block elements is removed, which can matter if your CSS displays those elements inline.
Does it minify inline JavaScript and CSS?
CSS inside <style> elements is minified. JavaScript inside <script> elements is kept as written apart from trimming leading and trailing whitespace, because safe JavaScript minification needs a full parser. Use the JavaScript minifier for scripts.
Which comments are kept?
Ordinary comments are removed. Internet Explorer conditional comments starting with <!--[if and comments starting with <!--! are kept, so you can mark license notices or server-side markers that must survive minification.
How much smaller will my HTML get?
Savings depend on how much indentation and how many comments the source contains. Heavily indented templates shrink noticeably, while HTML that is already compact changes little. If your server uses gzip or Brotli, the difference in transferred size is smaller than the raw difference.
Is the output still valid HTML?
The tool removes comments and spacing rather than acting as a full HTML validator. Valid source normally remains structurally similar, but whitespace-sensitive layouts and application-specific markup should be tested in the destination. Keep the original source and compare the rendered page.
Is my input uploaded?
Tools run in your browser. Files, text and results are not uploaded to our servers and are cleared when you leave the tool.
Your privacy comes first
Tools run in your browser. Files, text and results are not uploaded to our servers and are cleared when you leave the tool.