HTML Code Minifier
Compress HTML by removing comments and the whitespace between tags — while leaving pre, script and style content untouched.
Most of the weight a minifier can safely take out of HTML is the formatting itself: the newlines and indentation between tags, and the comments developers leave for each other. Removing the whitespace that sits strictly between two tags (the > … < gaps) and collapsing remaining blank runs typically takes 10–30% off a hand-indented page without changing a single element. The sample at the top, comment and all, goes from 73 characters to 50. This page does exactly that much and no more: attributes are never rewritten, optional tags are never dropped, and inline spacing inside a sentence is collapsed to single spaces rather than deleted, because in HTML a single space between words is content.
Minifying runs in this browser only — your HTML is never uploaded, stored or put into a link. The contents of <pre>, <textarea>, <script> and <style> elements are passed through untouched, because whitespace inside them is content, not formatting.
Quick answers
How do I minify HTML?
Remove comments and the whitespace between tags, and collapse other blank runs to a single space. “<div> <p>hello</p> </div>” with a comment inside minifies to “<div><p>hello</p></div>”.
Do not squeeze the inside of <pre>, <textarea>, <script> or <style> elements — there the whitespace is content. This tool lifts those blocks out first and restores them untouched.
Why should <pre> content never be minified?
Because <pre> exists to render whitespace exactly: code samples, tables typed in spaces and ASCII diagrams all deform if their spaces collapse. A safe HTML minifier treats <pre> contents as read-only.
The same applies to <textarea> default text and to string literals inside <script>, which is why all four element types are protected here.
How to use
- Paste your HTML into the top box.
- Read the minified result and the size line below it — characters before and after, with the percentage saved.
- Check any <pre> block in the result: its spacing comes through exactly as written, by design.
- Copy the minified HTML out. Keep your indented original as the file you edit; minified output is for serving, not for working in.
About this tool
The important exception is baked into the tool rather than left as a warning: the contents of <pre>, <textarea>, <script> and <style> elements are lifted out before minifying and put back untouched. Whitespace inside a <pre> is the content — squeeze it and code samples, ASCII diagrams and preformatted addresses deform. The same logic protects a script’s string literals and a textarea’s default text. One honest limit follows from that design: a literal "</script>" inside a script string would end the protected block early, the same constraint browsers themselves apply — such code needs the usual escaping either way.
Frequently asked questions
Why is the whitespace inside my <pre> still there after minifying?
Deliberately. A <pre> renders its whitespace, so the spaces and line breaks inside it are content, not formatting — minifying them would change what the page shows. This tool protects <pre>, <textarea>, <script> and <style> contents before touching anything else, then restores them exactly.
What does this minifier remove, exactly?
HTML comments, whitespace sitting between two tags, and runs of multiple spaces or newlines elsewhere (collapsed to a single space), plus leading and trailing whitespace of the document. It does not remove optional closing tags, shorten attributes, or touch attribute values.
How much smaller will my HTML get?
Usually 10–30% for indented, commented source; less for markup that was already compact. The size line under the result shows your exact numbers — for the sample on this page, 73 characters in and 50 out, roughly a third saved — rather than a generic claim.
Could minifying break my page?
The transformations here are the safe set, and the protected-element handling covers the classic breakage (squeezed <pre> blocks and scripts). Two things stay your responsibility: whitespace between inline elements is collapsed, not removed, precisely because a missing space can join two words; and a page built on invalid nesting can rely on parser quirks no minifier can promise to preserve.
First time embedding? Read the step-by-step guide →
More free tools
UUID Generator
Generate random v4 UUIDs in bulk.
JSON Formatter & Validator
Format, minify and validate JSON in one click.
What Is My IP
See your public IP address instantly. No sign-up, nothing stored.
Regex Tester
Test, check and validate regular expressions with live highlighting.
JWT Decoder
Decode a JWT token without the secret — see its header and payload.
SHA-256 Hash Generator
Generate SHA-256 / SHA-512 hashes instantly.