Minify HTML
Strip comments and whitespace, and shrink the CSS and JavaScript inside the page — without disturbing the spacing that actually renders. Your source is never stored.
- Never stored
- No queue, no waiting
- No signup, no watermark
The minified HTML appears here.
How it works
Paste your HTML
Or drop the file in. Nothing is stored — this matters more for source than for most things.
Choose how far to go
Comments, whitespace, inline CSS and inline JavaScript are each separate switches.
Copy or download
You are shown how much smaller it got, before and after.
The whitespace that matters, and the whitespace that does not
In HTML, a space between two inline elements is a real space, and this is what separates a careful minifier from one that breaks pages. Collapse the newline between two links and the words run together on screen; collapse the indentation inside a pre block or a textarea and the content itself changes, because whitespace there is content. So whitespace is only removed where it provably does not render, and left exactly alone where it does. A minifier that strips every space uniformly will produce a smaller file and a visibly wrong page.
Comments go, since they are for whoever maintains the source rather than for the reader — with the exception of conditional comments, which are instructions rather than notes. Redundant attributes are dropped: a type="text/javascript" on a script element has been the default for a decade, and method="get" on a form says what a form does anyway.
Removing attribute quotes is valid HTML and is off by default, deliberately. The specification permits an unquoted attribute value provided it contains no spaces or awkward characters, and browsers handle it perfectly. Template engines frequently do not: a Blade, Twig, Handlebars or JSX expression inside an unquoted attribute stops parsing correctly, and the failure appears at build time in a file nobody wants to read. The saving is small and the risk is not, so it is opt-in.
The honest measure of what this gains is after compression, not before. Servers send HTML gzipped or brotli-compressed, and those algorithms are extremely good at repeated whitespace — so a document that minifies from 100 KB to 70 KB may only go from 12 KB to 11 KB on the wire. Minifying HTML is worth doing and it is the smallest of the three; the stylesheet and the script are where the real weight is.
When you want something else
For a site rather than a file, this belongs in the build rather than in a browser tab. Every current framework and static site generator minifies HTML on build, and doing it by hand means it stops happening the moment somebody forgets. The libraries behind them are configurable down to individual transforms, which is worth reaching for when one particular rule is causing trouble.
Before optimising the markup, check what the page actually weighs. In almost every real site the HTML is a rounding error next to the images, the fonts and the JavaScript — Lighthouse or the browser's own network panel will tell you in seconds, and the answer is usually that an unoptimised hero image costs more than every byte of markup on the page.
Frequently asked questions
Is my code stored anywhere?
No, and for source code that is the point. Nothing is stored and no server ever sees it. Pasting proprietary source into an online minifier that posts it somewhere is a disclosure, whatever the site says about retention — and it is exactly the sort of thing that is done in a hurry without thinking.
Will minifying break how the page looks?
Not the way it is set up here. Whitespace is only collapsed where it does not render: between block elements such as divs and list items. The space BETWEEN INLINE elements is kept, because removing it visibly joins two words together — "</span> <span>" is a real space on screen and "</span><span>" is not. The contents of <pre> and <textarea> are left byte for byte alone. And removing optional closing tags is deliberately switched off: it is valid HTML, but a good many template engines and email clients parse the result badly.
What does it actually remove?
Comments, whitespace that never rendered, and the slack inside <style> and <script> blocks. Your markup structure, attributes and text are untouched — the tool is checked by parsing the page before and after and confirming the element count, the list items and the visible text are identical.
Should I remove attribute quotes?
Only if the output is going straight to a browser. It is valid HTML and it saves a little, but unquoted attributes break some template engines, some email clients and most naive parsers. It is off by default and the page warns you when you switch it on.
Does it minify the CSS and JavaScript inside the page?
Yes, both, the same way as our CSS and JavaScript minifiers. One exception: if your inline CSS uses native nesting or modern media queries, the CSS pass is switched off for that run — the CSS minifier predates those features and would silently delete rules. The HTML is still minified, and the page tells you that happened rather than handing back a page missing styles.
How much smaller will it get?
For hand-written HTML with indentation and comments, commonly 10–30%. Then gzip on your server does most of the remaining work — minifying first still helps, because the two compound, but do not expect minification alone to halve a file.
Can I minify a whole site at once?
One page at a time here. For a site with many pages, minify as part of your build or deploy step so every page is done the same way on every release — and keep the readable source in version control, never the minified output.
Good to know: Whitespace is only collapsed where it does not render, so text inside pre and textarea is left exactly alone and spaces between inline elements are kept. Removing attribute quotes is valid HTML but breaks some template engines, which is why it is off by default.
Put this tool on your website
Free for any blog, class page or help article. Paste one snippet and your visitors can use it right on your page.
Related tools
CSS Minifier
Shrink a stylesheet, or be told why not
JavaScript Minifier
Compress JavaScript — nothing is stored
XML Formatter
Indent XML so you can read it
Markdown Preview
See your Markdown the way GitHub renders it
Bijoy to Unicode Converter
Read SutonnyMJ text as real Bangla
Unicode to Bijoy Converter
Set Unicode Bangla in SutonnyMJ