Back to Tools

HTML Minifier

Compress your HTML by removing whitespace, comments, and empty lines

0
0
0%
Source HTML
1

Reduce the size of your HTML file

Indentation, blank lines and developer comments make source code pleasant to edit but add bytes that browsers never need. This minifier removes that overhead from pasted HTML and reports how much smaller the result is. It is a lightweight text-based squeeze: it does not rewrite your markup, rename anything or touch the logic of embedded code.

How to minify a document

  1. Paste your markup into the Source HTML editor. Load Sample inserts a short header-and-article example with a comment, useful for a first try.
  2. Look at the two checkboxes under the editor. Remove Comments and Collapse Whitespace are both ticked by default; untick either one to skip that step.
  3. Press Minify HTML Now.
  4. Read the header numbers: Original, Minified and Savings. Sizes are calculated in bytes and displayed as B, KB or MB, and the original size updates while you type.
  5. Take the result from Minified HTML Output using Copy or Download, which produces minified.html.

What each option changes

  • Remove Comments deletes everything between the comment opening and closing markers, across multiple lines.
  • Collapse Whitespace turns every run of spaces, tabs and line breaks into a single space, and then removes whitespace sitting directly between a closing bracket and the next opening bracket.

Nothing else is altered: attribute quotes, optional closing tags and inline CSS or JavaScript are left as they are.

When it is worth using

  • Trimming a static landing page or an HTML email body before uploading it.
  • Preparing a template string that will be embedded in a JavaScript file or a JSON payload on one line.
  • Estimating how much whitespace a hand-written page carries before you decide on a build step.
  • Making a long snippet short enough to paste into a form field with a character limit.

Watch out for these cases

Collapsing whitespace is applied to the whole text, so content inside pre or textarea will lose its line breaks and spacing. A line comment inside an inline script, written with two slashes, can swallow the code after it once line breaks are gone, so either keep Collapse Whitespace off for such pages or convert the comment first. Conditional comments used for old Internet Explorer versions are also removed when Remove Comments is on. Because it works on plain text with simple pattern matching, always load the minified page in a browser and check it before publishing. The percentage saved varies with how much indentation the original had.

Related Tools


Frequently Asked Questions

Does this minify CSS and JavaScript too?
No. It only removes comments and collapses whitespace across the whole pasted text. CSS and JavaScript inside style or script tags are not compressed or renamed, though their extra whitespace will be collapsed like anything else.
Can minifying break my page?
It can in specific situations. Content in pre or textarea loses its spacing, and an inline script that relies on line breaks, such as one ending in a double-slash comment, can stop working. Test the output in a browser first.
How is the savings percentage worked out?
It compares the byte size of your original text with the byte size of the minified text and shows the reduction as a rounded percentage. The size counts characters as bytes, so accented or emoji characters weigh more than plain letters.
Should I keep conditional comments?
If you still target old Internet Explorer with conditional comments, untick Remove Comments, because the tool deletes every comment including those. Most modern pages no longer need them, so the default setting is usually fine.
Can I get the original formatting back later?
Not from the minified file alone, because removed comments are gone for good. You can restore readable indentation with an HTML beautifier or formatter, but keep your original file for the comments.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.