HTML Minifier
Strip comments and collapse whitespace while preserving pre/code/script
Input
Minified Output
Minified HTML will appear here
About
This tool minifies HTML documents by removing comments and collapsing whitespace between tags, while preserving the content of <pre>, <textarea>, <script> and <style> elements. Use it to shrink static HTML before deploy or to trim pasted markup. Minification runs entirely in your browser; nothing is uploaded.
Examples
Minify a page with a code block
<div>
<!-- a comment -->
<h1>Hello</h1>
<pre>
code
</pre>
</div><div><h1>Hello</h1><pre>
code
</pre></div>Comments are stripped, inter-tag whitespace is collapsed, and the indentation inside <pre> is preserved exactly.
Strip redundant attribute quoting
<a href="/x" target=_blank rel="noopener noreferrer">Link</a><a href=/x target=_blank rel="noopener noreferrer">Link</a>Quotation marks are removed from attribute values that don't contain whitespace or special characters, shaving bytes without changing browser behavior.
About this tool
The HTML Minifier shrinks HTML source by stripping comments, collapsing inter-tag whitespace, and removing redundant quoting on attribute values, while preserving the byte content of <pre>, <code>, <textarea>, <script>, <style> and CDATA so code samples, inline scripts and stylesheets survive intact.
Useful when you need to ship smaller HTML — generated pages, email bodies, static-site output, or any markup that grew noisy in development and is now ready for production. Minification runs entirely in your browser; the input is never uploaded or stored.
How to use
Paste your HTML
Drop the markup into the input editor, or load a sample to see a quick before/after.
Choose options
Toggle comment removal, whitespace collapse, and attribute-quote cleanup. Whitespace inside <pre>, <code>, <textarea>, <script> and <style> is always preserved.
Copy the result
Click Copy to copy the minified HTML, or download it for use in production.
Use cases
Shrinking production HTML
Cut kilobytes from generated HTML before serving it, especially on content-heavy pages where the savings compound across impressions.
Sanitizing pastes before commit
Strip developer comments and excess whitespace from hand-edited templates so committed markup stays clean in version control.
Preparing email HTML
Reduce file size of HTML email bodies to avoid clipping by client-side size limits and improve mobile rendering speed.
Common mistakes
Mistake:Trusting minified output to be byte-identical except for whitespace.
Fix:Safe minifiers are conservative — they may collapse quotes, drop optional slashes, or remove boolean attributes. Always sanity-check the result before deploying.
Mistake:Applying minification to a debug build.
Fix:Minify only the production build. Source maps and readable markup matter when investigating real bugs, so keep the unminified version for development.
Mistake:Assuming whitespace inside arbitrary tags is preserved.
Fix:Only <pre>, <code>, <textarea>, <script>, <style> and CDATA are protected. Whitespace inside <p> or <div> is collapsed by design — that's the point.
Frequently asked questions
References & standards
Related tools
Driver's License Generator
Generate driver's license numbers in the correct format for 21 countries and all 50 US states, plus a format and Luhn validator — test data only, runs in your browser.
Address Generator
Generate realistic addresses in the correct format for 21 countries — single-line, multi-line, JSON or HTML — plus a postcode validator. Test data only, runs in your browser.
Phone Number Generator
Generate phone numbers in the correct format per country — mobile, landline and toll-free — in international, national, raw or tel: format, plus a validator. Test data only.
XML to JSON Converter
Convert XML data to JSON format with attribute handling, configurable parsing options, and live statistics
Markdown to HTML Converter
Convert Markdown to clean HTML with GitHub-Flavored Markdown, syntax highlighting, and optional sanitization
Docker Run to Compose Converter
Convert a docker run command into a docker-compose.yml service definition with full flag support