HTML Minifier Online
Compress HTML by stripping comments, collapsing whitespace and dropping redundant type attributes, without changing how the page renders. Indented, hand-written HTML shrinks the most: MDN's main HTML page lost 18% in our test.
Built and maintained by Muhammad Tayyab — Founder, DevPik.
Why Use HTML Minifier Online?
Next.js, Vite and most build tools already compact the HTML they emit, but plenty of landing pages, email templates and WordPress themes are still written and maintained by hand. Those files carry indentation and comments the browser never shows, and on MDN's main HTML page that was 18% of the bytes. Removing them means fewer bytes to download on slow mobile connections, and it helps wherever size is metered, such as HTML embedded in JSON payloads or email templates sent in bulk.
How to Use HTML Minifier Online
- Paste your HTML into the Original HTML panel.
- Pick your options. Remove comments, Collapse whitespace and Remove redundant attributes are on by default; Remove spaces between block tags, Remove attribute quotes and Minify inline CSS are off.
- Click Minify, then Copy. Changing an option re-runs the minifier, so the output always matches the boxes you have ticked.
- Read the byte counts in the bar below the panels: the original size, the minified size and the saving.
- Leave Remove spaces between block tags off if your CSS shows lists or blocks inline, such as nav menus and footer links, because the gaps between those items come from that whitespace.
Worked Examples
Strip comments and collapse whitespace
<!-- hero -->
<div class="hero">
<h1>Welcome</h1>
</div><div class="hero"> <h1>Welcome</h1> </div>
60 bytes to 42 (30% smaller) with the default options. With Remove spaces between block tags on, the output is <div class="hero"><h1>Welcome</h1></div> at 40 bytes.
Keep Outlook conditional comments and inline spacing
<!--[if mso]><table role="presentation"><tr><td><![endif]-->
<p>
Click <a href="https://example.com/offer">here</a> to claim it.
</p>
<!-- footer starts -->
<!--[if mso]></td></tr></table><![endif]--><!--[if mso]><table role="presentation"><tr><td><![endif]--> <p> Click <a href="https://example.com/offer">here</a> to claim it. </p> <!--[if mso]></td></tr></table><![endif]-->
204 bytes to 177 (13% smaller). The ordinary footer comment is gone, both [if mso] comments stay, and so do the spaces around the link, so the sentence still reads "Click here to claim it."
Collapse multi-line attributes
<a href="/signup" class="btn btn-primary" >Start</a>
<a href="/signup" class="btn btn-primary">Start</a>
56 bytes to 51. Line breaks inside a tag become single spaces; attribute values stay exactly as written.
Inline script left exactly as written
<script type="text/javascript"> // greet let name = "DevPik" console.log(name) </script>
<script> // greet let name = "DevPik" console.log(name) </script>
94 bytes to 71. The redundant type attribute goes, but the script keeps its // comment and line breaks, so code that relies on automatic semicolon insertion still runs.
About HTML Minifier Online
What this tool does: it reads your HTML as a sequence of tags, comments and text, the way a browser's tokenizer does, and rewrites it with fewer bytes. It removes comments, collapses each run of spaces, tabs and line breaks in text to a single space, drops whitespace that can never render (around the html, head and body tags and inside head), tidies the spacing inside tags, and removes type="text/javascript" and type="text/css", which browsers assume anyway. Everything inside pre, textarea, script and style is copied byte for byte, so preformatted text keeps its layout and inline JavaScript keeps its line comments and line breaks. It keeps the conditional comments Outlook needs (<!--[if mso]>), license comments that start with <!--!, and the small marker comments that React, Vue, Svelte, Solid, Lit and Qwik use to hydrate server-rendered pages. We checked the result on three real pages, Wikipedia's HTML article, MDN's main HTML page and the DevPik home page: before and after minifying, each rendered identically pixel for pixel in Chromium, and showed the same text once its scripts had run. Who it is for: anyone shipping HTML without a build step that minifies it for them. That includes developers maintaining landing pages by hand, teams pasting exported email templates into a sending service, WordPress theme builders, and anyone embedding HTML inside JSON payloads where byte size is metered. It also works as a quick check before a deploy: paste, minify and read the byte counts. Why an in-browser tool: many minifiers run on a server, so your markup, including internal copy, unreleased layouts and client work, gets uploaded somewhere you do not control. This one runs in your browser tab and sends nothing, so you can paste proprietary templates. There is no account and no queue, and results are instant. Practical gotchas: savings depend on the source. Indented, hand-written HTML shrinks the most; MDN's page went from 186,762 to 152,816 bytes (18.2%), while Wikipedia's article, which is already compact, lost 0.7% and the DevPik home page, rendered compactly by React, lost almost nothing. Minification does not replace gzip or Brotli on your server, and it saves less once they run: after Brotli, MDN's saving was 5.3%. Two cases depend on your CSS. An element other than pre or textarea that you style with white-space: pre keeps its spacing only if you switch Collapse whitespace off, and the optional Remove spaces between block tags changes the gaps between items your CSS displays inline. Finally, treat the minified file as a build artifact and keep the readable original in version control.
Troubleshooting & Common Issues
Minified page looks different from the source
With the default options the rendering should not change, so check two things. If you turned on Remove spaces between block tags, items your CSS displays inline or inline-block, such as nav menus and footer links, lose the gap between them: turn that option off. If an element other than `<pre>` or `<textarea>` has `white-space: pre` or `pre-wrap` in your CSS, its spacing collapses: turn Collapse whitespace off or move that content into a `<pre>`.
JavaScript stops working after minifying
Script contents are never changed, so look at the comments. Server-rendered pages from React, Vue, Svelte, Solid, Lit and Qwik use marker comments to hydrate, and the tool keeps those, but another framework's markers may be removed. Switch Remove comments off and minify again.
Meta tags or attributes look different
The tool never removes an element. The only attributes it drops are `type="text/javascript"` and `type="text/css"`, which browsers assume. Remove attribute quotes, which is off by default, writes `content=summary` instead of `content="summary"` only where the value has no spaces, quotes, equals signs or angle brackets, so the value itself never changes.
Server sends the minified file but the browser still sees the old version
Aggressive caching. Bust the cache by appending a query string (`?v=2`) or updating the filename. If the file is served from a CDN, purge the edge cache manually after a minification pass.
Frequently Asked Questions
How much can HTML minification reduce file size?
It depends on how much indentation and how many comments the source has. In our tests MDN's main HTML page went from 186,762 to 152,816 bytes (18.2%) and a page of indented cards with comments lost 33.5%, while Wikipedia's already compact HTML article lost 0.7% and the DevPik home page, rendered compactly by React, lost almost nothing. Hand-written and template HTML saves the most.
Does minification affect how the page renders?
Not with the default options. Comments and whitespace that cannot render are removed, and every run of whitespace that could render keeps one space. We minified Wikipedia's HTML article, MDN's main HTML page and the DevPik home page and rendered each before and after in Chromium: identical pixel for pixel. Two cases depend on your CSS: elements other than pre and textarea styled with white-space: pre, and the optional Remove spaces between block tags when your CSS displays lists or blocks inline.
Should I minify HTML in addition to CSS and JavaScript?
Yes, if nothing in your build already does it. CSS and JavaScript usually shrink more, and HTML minification adds a smaller saving on every page view.
Does the tool send my HTML to a server?
No. Minification runs entirely in your browser. Internal templates, unreleased landing pages and customer-specific HTML stay on your device, and nothing is uploaded.
Will this minifier break my inline JavaScript or <pre> blocks?
No. The contents of <script>, <style>, <pre> and <textarea> are copied through untouched, so line comments, string literals and preformatted text keep their exact whitespace. Only the markup around them is compressed. The one exception is the Minify inline CSS option, which removes comments and spacing inside <style> blocks. To minify the JavaScript itself, run it through a dedicated JavaScript minifier first.
Is it safe for HTML email templates?
Yes. Outlook relies on conditional comments such as <!--[if mso]>, and the minifier keeps those while removing ordinary comments. It also keeps the spaces between inline elements. Send yourself a test email after minifying, because some email clients rewrite or clip large messages.
Can I turn minified HTML back into readable code?
Only partly. Re-indenting is easy for a formatter, but the comments and the original line breaks that minification removed are gone for good, so the result will not match your source. That is why the safest workflow is to keep the readable file in version control and minify a copy when you deploy, rather than editing minified HTML directly.
Should I keep an unminified copy for debugging?
Yes. Commit the readable source to version control and minify only when you build or deploy. Debugging a 30 KB single-line HTML file in production is painful, so keep the source readable and let the build step produce the minified output.
Does HTML minification really impact Core Web Vitals?
Less than you might expect once the server compresses responses. On MDN's main HTML page, minifying saved 18.2% of the raw bytes, 9.9% after gzip and 5.3% after Brotli. A smaller document does arrive sooner, so it is worth doing, but turning on gzip or Brotli matters far more.
Guides & Further Reading
Diagram Design: The Claude Code Skill That Writes Taste Down
The model already understood your architecture. What it was missing was taste. Diagram Design writes the taste down as a loadable reference, and the result is diagrams that do not look generated.
12 min readLogo Design Skill: Turn Claude and AI Agents Into a Disciplined Logo Designer
Logo Design Skill is a free, MIT-licensed agent skill that turns Claude or any Agent Skills agent into a logo designer: a brief-to-checkpoint workflow, 1,400+ visually classified reference logos, dependency-free Python audit and export tools, and production-ready SVG output.
11 min readRelated Tools
JSON Formatter Online
Format, beautify, and validate JSON with syntax highlighting, a collapsible tree view, auto-fix for trailing commas and single quotes, search, and JSON-to-XML/CSV/YAML conversion.
Text to HTML Converter
Convert plain text with paragraphs and line breaks into semantic HTML. Auto-wraps paragraphs in <p> tags, links URLs and emails, and escapes special characters for safe rendering.
Markdown Converter
Convert Markdown (CommonMark and GitHub-Flavored) to clean semantic HTML with live preview. Handles headings, tables, code blocks, images, and lists for READMEs and blog posts.
URL Encoder Decoder Online
Percent-encode URL components or decode encoded strings. Supports encodeURIComponent and encodeURI modes for query parameters, full URLs, and handles Unicode characters correctly.
Was this tool helpful?