HTML Minifier
Paste HTML to remove comments and redundant whitespace and to minify inline CSS and JavaScript. Content inside <pre> and <textarea> is left exactly as written.
Runs in your browserNo sign-upNothing uploaded
How to use the HTML Minifier
- Paste an HTML document or fragment, or open an
.htmlfile. - Choose what to remove: comments, whitespace, and whether inline
<style>and<script>blocks should be minified too. - Check the warnings line: an inline script with a syntax error is kept unchanged rather than breaking your page.
- Copy the minified HTML or download it.
What gets removed?
- Comments:
<!-- … -->is removed, except Internet Explorer conditional comments and comments starting with<!--!. - Whitespace between block elements: newlines and indentation between tags like
<div>,<li>or<head>never render, so they are dropped completely. - Runs of spaces in text: they collapse to a single space, which is exactly how the browser renders them anyway.
- Whitespace inside tags:
<p class = "a">becomes<p class="a">.
What is preserved?
Whitespace is significant in some places, and the minifier respects them. Content of <pre> and <textarea> is kept byte for byte. A single space between inline elements, such as <b>bold</b> text, is kept because removing it would join the words. Attribute values and quotes are never changed.
Inline CSS and JavaScript
Inline <style> blocks are optimized with CSSO and inline <script> blocks with Terser, the same engines used on the CSS minifier and JavaScript minifier pages. JSON-LD and other JSON script blocks are compacted, and scripts of unknown types (for example templates) are left alone.
Is HTML minification worth it?
For server-rendered pages and static sites the HTML document is the first thing the browser downloads, so every saved byte shortens time to first render. Savings of 10–25% before compression are common, more for heavily indented templates and pages with large inline scripts.
Frequently asked questions
Will minifying HTML change how my page looks?
<pre>/<textarea> content is untouched. If you style elements with white-space: pre in CSS, turn off Collapse whitespace.