Minify HTML without breaking your layout
The HTML Minifier makes web pages smaller by removing comments and the indentation and line breaks that browsers ignore. Paste a page or load an .html file and the minified markup appears instantly, with the size before and after, the percentage saved and an estimate of the gzipped size.
Whitespace in HTML is subtle. The space in <b>rye</b> <i>bagels</i> is visible on the page, while the line breaks between <li> items in a list are not. This minifier parses your markup properly and knows the difference: it removes whitespace only next to block-level tags, keeps a single space between inline elements and text, and never touches the contents of <pre>, <textarea>, <script> or <style> unless you ask it to minify the code inside.
Everything runs in your browser, so unpublished pages, templates and email HTML stay on your device.
How to use the HTML Minifier
- Paste your markup into the HTML to minify box, drop an .html file onto it, or press Load file.
- Choose the options: remove comments (optionally keeping IE conditional comments), minify inline CSS, minify inline JavaScript and JSON, and remove default type attributes.
- Pick a Whitespace mode — Collapse for the smallest output, Conservative if your CSS turns block elements into inline-block, or Keep to leave spacing alone.
- Read the minified HTML on the right; it updates as you type. Any error is shown with its line and column, and notes explain anything left unchanged.
- Press Copy or Download .html to save the result.
HTML Minifier features
Whitespace rules that match the browser
Spaces between inline elements and text are kept, so words never run together, while indentation around blocks, lists, tables and the head is removed.
Protected content
<pre> and <textarea> are copied byte for byte, and scripts and styles are only changed when you tick their minify options.
Inline CSS minification
Code in <style> blocks and style="" attributes goes through the same careful tokenizer as the CSS Minifier.
Optional JavaScript and JSON
Inline scripts are minified with Terser, loaded on first use; JSON-LD and import maps are compacted without changing a single value.
Attributes kept safe
Attribute order, quotes and values are preserved; only class lists are tidied and redundant type attributes on scripts and stylesheets are dropped.
Clear errors
An unclosed tag, comment or attribute quote is reported with its exact line and column instead of producing broken markup.
How whitespace is handled
Browsers collapse any run of spaces, tabs and line breaks in normal text into a single space, and they do not draw whitespace at the start or end of a block such as a paragraph, list item or table cell. In Collapse mode the minifier applies exactly those rules: runs become one space, and whitespace touching a block-level tag, or sitting between elements in the <head>, is removed.
There is one case the minifier cannot see: CSS that changes how elements are displayed. If your stylesheet makes list items or divs display: inline-block, the line breaks between them create small visible gaps, and removing them closes those gaps. Choose Conservative mode for such pages — it collapses every run of whitespace to a single space but never removes it completely.
| Input | Collapse mode | Why |
|---|---|---|
<li>A</li>⏎ <li>B</li> | <li>A</li><li>B</li> | Whitespace between list items is never rendered |
<b>Hi</b> <i>there</i> | <b>Hi</b> <i>there</i> | The space between inline elements is visible |
<p>⏎ Text⏎</p> | <p>Text</p> | Leading and trailing space in a block is not drawn |
<pre> a⏎ b</pre> | Unchanged | Pre-formatted text keeps every space |
What is never changed
- The text inside
<pre>,<textarea>and elements nested in a<pre>. - Attribute values (other than class lists and minified style attributes), attribute order and the quotes you used. Optional quotes and optional closing tags are left in place.
- Character references such as
and©, and the non-breaking spaces they produce. - Scripts with other types, such as
text/templateortext/x-handlebars, which may depend on their exact whitespace. - IE conditional comments, as long as “Keep IE conditional comments” is ticked, because older Internet Explorer versions read them as instructions.
Getting the most out of minified HTML
HTML minification typically saves 10–25% on hand-written pages and more on templates with deep indentation or long comments. Combine it with gzip or Brotli compression on your server, and minify your stylesheets and scripts too with the CSS Minifier and JS Minifier. To turn minified markup back into something readable, use the Code Beautifier, and to check how a page renders, open it in the HTML Viewer.
HTML Minifier FAQ
Is this HTML minifier free and private?
Yes. It is free, has no limits and needs no account. The HTML is processed entirely in your browser and is never uploaded.
Will minifying HTML change how my page looks?
In Collapse mode the page looks the same unless your CSS sets block elements such as list items to inline-block, in which case gaps between them can close. Use Conservative mode for those pages; it never removes a space completely.
Does it minify the CSS and JavaScript inside my HTML?
Yes, optionally. “Minify inline CSS” compresses <style> blocks and style attributes. “Minify inline JS & JSON” compresses scripts with Terser and compacts JSON-LD and import maps. If a block cannot be parsed, it is left unchanged and a note tells you where.
Why are some comments kept?
IE conditional comments such as <!--[if lt IE 9]> are instructions for old Internet Explorer versions, so they are kept unless you untick that option. Untick “Remove comments” to keep every comment.
Does it remove optional tags or attribute quotes?
No. Removing optional closing tags and quotes saves a few more bytes but makes markup fragile and harder to edit, so this tool keeps them for safety.
Can I minify email templates or SVG with it?
Yes. Email HTML and inline SVG are handled like any other markup — whitespace between SVG shapes is removed while text inside <text> elements keeps its spaces. Test emails in your mail client afterwards, as some clients are unusually strict.