Minifies HTML and protects whitespace inside <pre>, <code>, and <script> tags; unlike the CSS minifier, no comment is ever preserved.
Introduction
HTML written for editing and HTML delivered to a browser don't need to be the same file. While you're building a page, indentation and line breaks make the structure easy to follow, and comments left in the markup explain sections or leave notes for later. A browser doesn't need any of that to render the page correctly — it just needs valid, well-formed tags. Minifying strips out what's there purely for a human reader, so the same page reaches the browser as a smaller file.
How This Tool Minifies Your HTML
- All comments are removed, with no exceptions. Every
<!-- ... -->block is stripped, including old-style Internet Explorer conditional comments and any comment you might have wanted to keep, such as a license or attribution note. There's no equivalent here to the "keep this one" convention this site's CSS minifier supports — if a comment matters, keep it in your working copy and don't rely on it surviving minification. - Content inside
<pre>,<code>,<script>, and<textarea>tags keeps its exact whitespace. Line breaks and spacing are meaningful inside these tags — a code sample or a block of preformatted text would render wrong if its internal spacing got collapsed — and this tool leaves that whitespace untouched. - Whitespace elsewhere is collapsed, not deleted. A run of spaces, tabs, or line breaks between two inline elements (a link inside a sentence, for example) is reduced to a single space rather than removed outright, so words next to each other don't get glued together. Only the space between top-level structural tags and inside
<head>is trimmed away entirely, since nothing there is ever visibly rendered as running text. - A trailing self-closing slash is normalized away.
<img src="photo.jpg" />becomes<img src="photo.jpg">— both are valid HTML, and the shorter form saves a few characters on every self-closing tag in the page.
The One Real Risk: Comments Inside Preformatted Content
Because comment removal happens as a first pass over your entire input, before this tool looks at which tag anything is inside, it can't tell the difference between an ordinary comment meant to be deleted and the literal text <!-- ... --> that you're deliberately displaying inside a <pre> or <code> block — for example, a code sample in a tutorial that shows what an HTML comment looks like. In that specific case, the example text would be stripped out even though the whitespace around it inside the same block is preserved correctly. This only affects text that literally contains the characters <!-- and --> inside a preformatted block; it doesn't affect ordinary code samples that don't include comment syntax as part of what they're showing.
What to Know Before You Minify
This tool changes formatting only — it doesn't reorder elements, merge tags, or remove anything from the page's actual structure. There's no size limit on what you can paste, since you're working with text directly rather than uploading a file; a page's full HTML, even a long one, pastes and processes the same way as a short snippet.
As with any minifier, it's worth loading the minified output in a browser before publishing it — not because the conversion is unreliable, but because it's good practice to confirm a page looks and behaves the way you expect before it goes live, the same as proofreading anything else before submitting or publishing it.
When This Is the Right Tool
- Preparing a page for publishing after you're done editing. Keep working with the readable version while you build the page, and minify once, right before it goes live — not as a working format.
- Cutting page weight on limited hosting or a slow connection. A smaller HTML file downloads faster, which matters more than it might seem on a school network or a phone on mobile data.
- Comparing source code to see what production HTML actually looks like. Viewing the source of a real website often shows compact HTML that looks nothing like what you write by hand — minifying your own page and comparing it side by side is a concrete way to see why.
Example
A student finishes a personal portfolio page for a web-design class, with comments left throughout the markup from earlier drafts, plus a code sample inside a <pre> block showing what an HTML comment looks like, as part of explaining what they learned. Before submitting the project, they paste the full page here. The rendered page looks and behaves exactly the same, the leftover draft comments are gone, and the file is smaller — but the comment example inside the code sample is also gone, since it happened to contain the literal <!--/--> characters. Adjusting that one example to avoid the exact comment syntax, or leaving that section out of what gets minified, avoids the problem.
FAQs
Will minifying change how my page looks?
No. Tags and structure are preserved — only formatting, whitespace, and comments change, none of which affect how the page renders.
What happens to comments in my HTML?
All of them are removed, with no exceptions — there's no way to mark a comment as one to keep, unlike this site's CSS minifier.
Is whitespace inside a <pre> or <code> block preserved?
Yes, the spacing and line breaks inside those tags, and inside <script> and <textarea>, are left exactly as you wrote them. The one exception is if that content literally includes comment syntax (<!-- -->) as text you're displaying — that gets removed along with genuine comments, since comment removal happens before this tool looks at which tag it's inside.
Is there a size limit?
No — you're pasting text, not uploading a file, so there's no fixed limit the way there is on this site's file-upload tools.
Is my code saved anywhere?
No. The pasted HTML is processed to produce the minified result and isn't stored as a file or kept afterward; only the fact that the tool was used is recorded, not the code itself.
Which related tools can I use?
For other code formats, use CSS Minifier and JavaScript Minifier to minify, or CSS Beautifier and JavaScript Beautifier to reverse the process.