HTML Minifier
Minify HTML online: remove comments and collapse whitespace while keeping pre, textarea, script and style blocks intact. See the size saved instantly.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the HTML Minifier
The HTML Minifier shrinks pages by removing comments and collapsing whitespace, while leaving <pre>, <textarea>, <script> and <style> blocks untouched so nothing breaks.
Everything runs in your browser, so your input is never uploaded to a server.
How to use the HTML Minifier
- Paste HTML or open a file.
- Choose whether to remove comments.
- Copy or download the minified markup.
Example
Input
<!-- Card component -->
<div class="card">
<h2> Pricing </h2>
<p>
Start free, upgrade any time.
</p>
<pre> keep this spacing </pre>
</div>Result
<div class="card"><h2> Pricing </h2><p> Start free, upgrade any time. </p> <pre> keep this spacing </pre> </div>
The comment is removed and runs of whitespace collapse to one space, but the <pre> block keeps its spacing exactly.
Common mistakes
- Removing conditional or licence comments. Some comments matter, such as licence notices or server-side include markers. Switch off "Remove comments" when a page relies on them.
- Inline elements losing their space. Whitespace between inline elements, as in <b>Hello</b> <i>world</i>, is collapsed to one space but never removed, so words do not run together.
- Minifying templates. Template syntax such as {{ }} or <?php ?> is treated as text. Minify the rendered HTML instead of the template if the result looks wrong.
Works well with the HTML Minifier
- HTML Formatter: make minified markup readable again.
- CSS Minifier: minify the page’s stylesheet too.
- JavaScript Minifier: minify its scripts with Terser.
Frequently asked questions
Why are <pre> and <textarea> left alone?
Whitespace inside them is displayed to the user, so collapsing it would change the page.
Can I keep comments?
Yes. Switch off "Remove comments" to keep them, for example licence notices.
Are inline scripts and styles minified?
No. <script> and <style> blocks are kept as they are, so they cannot break. Minify them separately with the JavaScript and CSS minifiers.
How much smaller will my page be?
Typically 5–20% before compression, depending on how much indentation and how many comments the markup has. The saving is shown below the output.
Guides and tutorials
- Code Quality & Workflow
What Does Minification Actually Do? JavaScript, CSS and HTML Explained
What JavaScript, CSS and HTML minifiers really change, with before-and-after output, real size measurements, minification vs gzip, and what can break.
· 6 min read
- Web Development
How to Make an HTML Email Signature That Works in Gmail and Outlook
Build an email signature that looks right everywhere: tables, inline styles, hosted images, dark mode, Gmail's size limit and install steps for each client.
· 6 min read
Related tools
JSON Minifier
Minify JSON online by removing all unnecessary whitespace, and see how many bytes you saved. Invalid JSON is reported with its line and column.
CSS Minifier
Minify CSS online: strip comments, whitespace and redundant semicolons to shrink your stylesheet, and see the bytes saved. Runs in your browser.
JavaScript Minifier
Minify and mangle JavaScript online with Terser for smaller bundles. Supports modern ES syntax, with compress and mangle options and the size saved.
XML Minifier
Minify XML online by removing whitespace between tags, with an option to keep comments. Malformed XML is reported with its location.
SQL Minifier
Compress SQL queries onto a single line online, removing comments and redundant whitespace. Useful for logs, config files and embedding SQL in code.
JSON Formatter
Format and beautify JSON with configurable indentation and optional key sorting. Errors are reported with exact line and column.