HTML Minifier Online
Minify HTML, CSS & JavaScript online — or beautify minified code back into readable formatting. Pick a tab, paste your code, hit Compress. 100% client-side — your code never leaves your browser.
Minify HTML Online in Seconds
Every extra kilobyte of HTML, CSS, or JavaScript slows your page down and costs your visitors bandwidth. This free HTML minifier online strips the parts browsers simply don't need — comments, indentation, and redundant whitespace — and hands you compact, production-ready code you can paste straight into your deployment pipeline.
How to Minify HTML Online
- Pick the HTML tab above (or CSS / JS for those formats).
- Paste your code into the input box — from a view-source copy, a template file, or your editor.
- Hit Compress, then Copy Output. The minified code is ready to deploy.
What This Tool Compresses
- HTML comments —
<!-- ... -->blocks are removed unless they are IE conditional comments. - Whitespace between tags — indentation and blank lines collapse away. Spaces that matter between inline elements are kept, so words never run together.
- CSS & JavaScript — the same page minifies stylesheets and scripts with comment removal and token-aware JS compression.
Content inside <pre>, <textarea>, <script>, and <style> is preserved byte-for-byte, so your rendered layout and embedded logic never break.
Three Modes: HTML, CSS and JavaScript
Each tab is a different compressor with a different job. They share one rule: never change what the code means — only how much of it you have to ship.
- HTML — tokenizes the document and removes comments (except IE conditional comments such as
<!--[if IE]>), collapses whitespace runs inside text, and drops the whitespace between block-level tags. Where an inline element meets text —<span>a</span> <span>b</span>— a single space is kept instead of deleted, because removing it would glue the words together on screen. - CSS — removes block comments and whole-line
//lines, then collapses the whitespace around{ } ; : , > ~. Quoted strings and everything insideurl(...)are copied verbatim, sohttps://URLs, protocol-relativeurl(//cdn…)paths anddata:URIs survive intact. - JavaScript — removes comments, strips indentation and inline whitespace, and keeps strings, template literals and regex literals exactly as written. It does not rename your variables; that is a different (and much riskier) kind of tool.
What Stays Exactly As It Was
These are the cases where a naive whitespace-stripper quietly destroys code. On this page they are protected by construction and covered by an automated test suite:
<pre>,<textarea>,<script>and<style>bodies — never touched, byte for byte. Code samples and inline scripts keep their exact formatting.url(...)and quoted strings in CSS — adata:image/png;base64,…URI contains;and,, and anhttps://URL contains//. Both look like CSS punctuation but are not, so they are masked before any reformatting happens.calc(100% + 20px)— the+and-operators insidecalc()require surrounding whitespace. The CSS minifier deliberately leaves the+alone; saving two bytes is not worth emitting invalid CSS.- String concatenation vs. increment in JS —
a + +bstaysa+ +b, nota++b.a - -bstaysa- -b. Comments and division are not confused with regex literals.
Why the JavaScript Minifier Keeps Your Line Breaks
JavaScript inserts semicolons for you, and it can only do that where a line ends. Two lines that look independent are sometimes not:
let a = b
(function(){ /* … */ })() // called with b — not a separate statement
function f() {
return // returns undefined; the 1 below is dead code
1
}
Join those lines onto one row and both snippets change meaning while still running without an error. So the JS mode deletes indentation and comments but keeps the line breaks themselves. The output is a little larger than a mangler that flattens everything; the difference is that the flattened one can be wrong in ways you only notice in production.
What This Minifier Deliberately Does Not Do
- Strip optional tags or attribute quotes.
</li>andclass="row"are left alone — that trick is legal HTML but breaks naive parsers and template engines downstream. - Rewrite HTML entities.
stays . - Rename or mangle JavaScript identifiers, remove dead code, or inline modules. That is what a full build-time bundler does; this tool will not touch the names you can read.
- Inline CSS or JS, or rewrite asset URLs. Output stays one file of the same kind you pasted in.
- Replace gzip or Brotli. Those work at the transport layer and stack with minification — minify first, then let your server compress.
- Batch a folder, a zip, or a build step. One document per tab, straight from the textarea — no upload, no install, nothing to configure.
- Guarantee the output is smaller. If the input is already minified, the result can be identical or a few bytes longer where whitespace was load-bearing.
How Much Smaller Will the File Get?
It depends entirely on how much of the source is indentation and comments. Measured on real files:
- A hand-written template with comment banners and deep nesting: 357 → 270 bytes (24% smaller).
- Content-heavy production pages (lots of text, modest indentation): 1.5% – 4.4% smaller.
That is the honest split: minification is a reliable couple of percent on markup plus a real win on hand-formatted templates and stylesheets, and it is not a substitute for compression on the wire. If you want a quick before/after on your own file, paste it in and watch the character counters on each pane.
How to Check a Minified Page Still Renders the Same
- Keep the original — this tool only replaces what is in the output box, so copy the input back out first if you need it.
- Deploy the minified file to a staging URL and open both versions side by side.
- Open the browser console on the minified page. A syntax error that minification introduced shows up immediately and loudly.
- Spot-check the things whitespace depends on: inline links and buttons (no glued words),
<pre>blocks, CSScalc()andurl()values, and any inline script that builds markup from strings.
Why Minify HTML?
- Faster page loads — a smaller HTML document means a quicker First Contentful Paint and a better Core Web Vitals score.
- Lower bandwidth — every visitor downloads less, which matters even more on mobile data plans.
- Cleaner deployments — hand-written templates ship minified to production while you keep a readable source copy.
Frequently Asked Questions
Is this HTML minifier really free?
Yes — completely free, with no sign-up, no usage limits, and no watermarks. Minify as much HTML, CSS, or JavaScript as you like, right in your browser.
Is my HTML code uploaded to a server?
No. The HTML minifier runs 100% client-side in your browser. Your code never leaves your device, which makes it safe for proprietary templates and snippets.
Can I minify CSS and JavaScript with this tool too?
Yes. Switch between the HTML, CSS and JS tabs. Every mode uses syntax-aware compression so strings, regex literals and template content stay intact.
What does this HTML minifier online remove exactly?
From HTML: comments (IE conditional comments are kept), indentation, blank lines, and whitespace between block-level tags — while keeping one space wherever inline elements or words would otherwise run together. From CSS: block comments, whole-line // lines, and whitespace around { } ; : , > ~. From JavaScript: comments, indentation and inline whitespace. It never strips optional closing tags, attribute quotes, HTML entities, or variable names.
Why does the JavaScript minifier keep my line breaks?
Because JavaScript inserts semicolons at line ends. Joining lines can change behaviour silently: return followed by a value on the next line returns undefined, and let a = b followed by (function(){})() becomes a function call on b rather than two statements. Indentation is removed, the line breaks are not.
How much smaller will my file get?
It depends on how much of the source is indentation and comments. Measured on real files: a hand-written template with comment banners and deep nesting went 357 → 270 bytes (24% smaller), while content-heavy production pages only shrink by 1.5%–4.4%. Hand-formatted stylesheets and scripts usually save the most.
Does minifying HTML replace gzip or Brotli?
No, and it does not need to — the two stack. Minification removes bytes that are never part of the rendered page; gzip or Brotli then compresses what is left at the transport layer. Minify first, then let your server or CDN compress the response.
Can I minify a whole folder or a zip of files?
No. This is a one-document-at-a-time tool: paste into the input pane, compress, copy the output. There is no batch mode, no upload, no CLI and no build plugin — which is also why nothing is ever sent to a server. For whole projects, a build-time minifier is the right tool.
Can I get the original formatting back after minifying?
Not exactly — comments and blank lines are gone for good, so keep a copy of the source. You can, however, make minified HTML readable again with the Beautify button: it re-indents tags and puts each element on its own line so the structure is easy to follow.