Smaller HTML downloads faster and costs less bandwidth. An HTML minifier gets there by stripping what browsers do not need: comments, indentation, line breaks and repeated spaces. This HTML minifier does that in your browser, keeps the parts of a page where white space matters, and tells you how many bytes it saved.
What the HTML minifier changes
Paste a page or a fragment and press Minify. The tool removes comments, collapses runs of white space into a single space, drops white space beside block-level tags and tidies the spacing between attributes inside each tag. It does not rename classes, shorten attribute values, or remove optional tags. That conservative approach keeps the page behaving the same.
Why white space needs care
HTML keeps white space. White space between tags becomes text nodes in the page, and the idea that HTML ignores white space is a common misconception. It is collapsed only when the page is rendered by CSS. [1] By default, runs of spaces and tabs collapse to one space and line breaks become spaces, while non-breaking spaces are not collapsed. [1]
That is why a blanket search-and-replace on spaces is risky. Two inline elements with a space between them, like a bold word followed by an italic word, show a gap on screen. If the space is removed the words join. This minifier keeps a single space between inline elements and only removes white space next to tags such as div, p, li, table, head and script, where it never shows.
Content that is never touched
- pre blocks, where line breaks and spaces are shown as written.
- textarea content, which is the default text in a form box.
- script content, which is code rather than markup.
- style content, which is CSS.
The parser also strips a single leading newline from pre content, which this tool leaves alone. [1] These four elements are matched as a whole and copied out unchanged, so their text is exactly what you pasted.
Options
- Remove comments: deletes comments except conditional ones such as those that start with an if marker.
- Collapse white space: the main saving. Turn it off to remove comments only.
- Tidy tag spacing: squeezes repeated spaces and line breaks between attributes. Text inside quotes is never changed.
Worked example
Paste a div that contains a comment, a paragraph with three spaces between words and some blank lines. The output is one line: the opening div, the paragraph with a single space between words and the closing div. The comment is gone and the page shows the same text. The result box reports the bytes before and after and the percentage saved.
How much will it save?
Savings depend on how the HTML was written. Hand-indented templates with many comments often shrink by a fifth or more. HTML already produced by a build tool may shrink little. If a page is mostly inline script or style, the saving is small because those blocks are left alone. Web servers usually also compress responses with gzip or Brotli, which already squeezes repeated spaces, so the benefit of minifying is smaller on compressed transfers but still worth having for the final size.
When to minify
- Static pages and email templates where every byte counts.
- Snippets you embed in a script or a configuration string.
- The final build step, never the source you edit.
Minifying and compression together
Minifying and server compression solve related problems in different ways. Minifying removes characters that the page does not need, so the file is smaller before it is sent. Compression such as gzip or Brotli then encodes what remains more efficiently. Using both gives the smallest transfer, and a minified file also costs the browser a little less to parse. For pages that are built once and served many times, such as landing pages and documentation, the extra step is cheap and worth doing as part of your release process.
Keep your original, indented source in version control and treat the minified output as a build artefact that you regenerate whenever the source changes.
Common mistakes
- Minifying the file you edit. Keep the readable version and publish the minified copy.
- Removing the space between inline elements by hand.
- Expecting the tool to minify CSS or JavaScript inside style and script tags. Use a dedicated CSS and JavaScript minifier for that.
- Minifying a pre block by other means, which changes how code samples appear.
Check the result
After minifying, open the page in a browser and compare it with the original. Pay attention to spacing between links, buttons and other inline items, since that is where white space shows. If something looks tight, turn off Collapse white space and keep only comment removal.
Privacy
Your HTML never leaves your browser. The minifier is plain code in the page, so there is no upload and no waiting.
Related tools
For the opposite job, the HTML formatter and beautifier restores indentation. The CSS and JavaScript minifier shrinks the code inside style and script tags, and the HTML entity tool helps when special characters need escaping.
What next
Use this often? Add HTML Minifie to your Home screen.
Frequently asked questions
What does an HTML minifier remove?
Comments, repeated spaces and line breaks, and the white space between block-level tags. It also tidies the spacing inside tags. The page renders the same in a browser.
Will minifying HTML change how my page looks?
It should not. White space between inline elements is kept as a single space, because it can show on screen. Content in pre, textarea, script and style is left exactly as written.
Why keep a space between inline tags?
Browsers treat white space between elements as real text. A single space between two inline elements shows as a gap, so removing it can join words together.
Are conditional comments kept?
Yes. Comments that start with an if or endif marker are kept, along with the doctype, because browsers or tools may act on them.
Is my HTML uploaded?
No. Minifying runs in your browser and the result appears on this page only.
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.