What is HTML minification?
HTML minification removes characters the browser doesn't need — extra whitespace, comments, and the padding inside inline CSS and JavaScript — so the file downloads faster. This tool uses html-minifier-terser, a parser-based minifier, with settings that don't change how the page renders. All processing happens in your browser.
Why minify HTML
Minifying HTML removes everything a browser does not need to render the page — whitespace between tags, line breaks, comments, and redundant attributes — to make the file smaller. A smaller HTML document downloads faster and, on a busy site, the saved bytes add up across every request, improving load time and Core Web Vitals.
Done carefully, the page renders the same. This tool collapses runs of whitespace to a single space instead of deleting them, because a space between two inline elements such as links or bold text is visible, and it leaves <pre>, <textarea>, and the contents of scripts and styles it doesn't minify exactly as written.
What this minifier changes, and what it never touches
It collapses whitespace to single spaces, removes comments (keeping conditional comments and <!--! --> comments), drops quotes around attribute values where HTML allows it, and minifies <style> blocks, style attributes, <script> blocks, and event handlers with clean-css and Terser. It also tidies a few attribute values in ways browsers read identically: spaces around URLs and numbers, class lists, srcset lists, media queries, and the viewport and Content-Security-Policy meta tags.
It never changes text, text-bearing attributes such as title, alt, and form values, the URLs themselves, or the doctype, and it doesn't remove optional closing tags. If an inline script or style has a syntax error, it is left exactly as written and the tool shows the error. One limit: the minifier can't see your stylesheet, so whitespace inside an element that your CSS sets to white-space: pre, pre-wrap, or pre-line is still collapsed. Keep that content in a <pre> element instead.
A build step, not a source format
You should still write and maintain readable, indented HTML. Minify as the last step before serving, keeping the formatted version as your source of truth. That way your code stays easy to work with while your users get the smallest possible download.
Minification and gzip together
Minifying and server compression such as gzip or Brotli work together, not instead of each other. Minifying removes redundant characters, then compression shrinks what remains, and the combination is smaller than either alone — which is why production sites do both.
How to minify HTML
- 1Paste your HTML. Paste a document or fragment, or load the sample. The minified result appears as you type.
- 2Choose what to minify. Remove comments and Minify inline CSS & JS are on by default. Turn either off to keep comments or leave inline code as written.
- 3Check the result. The stats show the exact size before and after. A warning appears if an inline script or style has an error and was left unchanged.
- 4Copy the result. Use Copy output for the minified HTML, and keep your formatted copy for editing.
Examples
Compress a fragment
Input
<div> <!-- nav --> <p>Hello</p> </div>
Output
<div> <p>Hello</p> </div>
Spacing between inline elements
The space between Hello and world is visible, so it is collapsed to one space, not removed.
Input
<p><b>Hello</b> <i>world</i></p>
Output
<p><b>Hello</b> <i>world</i></p>
Inline CSS
Input
<style>
body { color : red ; }
</style>Output
<style>body{color:red}</style>What this minifier changes
Every change leaves the rendered page the same.
| Changed | Left exactly as written |
|---|---|
| Runs of whitespace, collapsed to one space | Text, and <pre> and <textarea> contents |
| Comments (optional) | Conditional comments and <!--! --> comments |
| Inline CSS and JavaScript (optional) | Scripts and styles with syntax errors |
| Quotes around simple attribute values | Titles, alt text, form values, URLs, and the doctype |
Frequently asked questions
Does minifying change how the page looks?
No, with one exception. The tool collapses whitespace to single spaces instead of deleting it, keeps <pre> and <textarea> contents exactly, and never edits text, URLs, or text-bearing attributes such as title, alt, and form values. The exception: whitespace inside an element that your CSS sets to white-space: pre, pre-wrap, or pre-line is collapsed, because the minifier can't see your stylesheet.
Why is there still a space between some tags?
A space between inline elements, such as two links or a word and a bold tag, is part of the rendered text. Removing it would join the words, so the tool collapses whitespace to one space instead of deleting it.
How much smaller will my HTML be?
It depends on how much indentation and how many comments the source has. The tool shows the exact size before and after, in bytes.
Does it remove content inside <pre> or <textarea>?
No. Their contents are kept byte for byte.
Does it minify inline CSS and JavaScript?
Yes, with Minify inline CSS & JS on. <style> blocks and style attributes go through clean-css, and <script> blocks and event handlers such as onclick go through Terser. JSON-LD and other non-JavaScript script types are not minified. A script or style with a syntax error is left unchanged, and the tool shows the error.
Should I keep a readable copy?
Yes. Maintain formatted HTML as your source and minify as a build step, so your code stays editable while users get the smaller file.
Is my HTML private?
Yes. Minification runs in your browser. The only exception is the Share link button, which uploads the current output when you click it.
Is it free?
Yes — free with no limits.