HTML Minifier
Minify HTML.
Loading tool…
What is HTML minification?
HTML is the structure of a web page: elements, attributes, and the text between them. Source HTML carries a lot the browser does not need — indentation, line breaks between tags, developer comments, and sometimes redundant attribute quoting.
Minification strips those. It also collapses runs of whitespace between elements, removes optional closing tags where the specification permits, and can inline-minify embedded style and script blocks. The one genuine hazard is whitespace inside content: in HTML, the space between two inline elements is meaningful and rendered, so an over-aggressive minifier can visibly close a gap between words or links. A good minifier collapses whitespace without deleting it entirely, which is why you should always eyeball the result.
Why we built this tool
Markup minification pays off most where pages are large and repetitive — generated tables, catalogue listings, email templates, and static sites with hundreds of pages — and on HTML email, where several clients still impose hard size limits and clip anything longer.
Templates and unreleased pages are client work, and there is no reason to hand them to a third-party server for whitespace removal. Ours parses and rewrites the markup in your browser, so the page source stays on your device, has no size limit, and needs no account. It is also fast enough to sit in your workflow as a final step before you paste the output into a production template.
Tips and common mistakes
- Check spacing between inline elements after minifying — this is the one place aggressive whitespace removal is visible.
- Preserve content inside
<pre>and<textarea>, where whitespace is meaningful. - Conditional comments still matter for older Outlook rendering in HTML email; do not strip them there.
- Keep HTML email under roughly 102 KB so Gmail does not clip the end of your message.
Open HTML Minifier with a link
Assistants and scripts can open HTML Minifier with its input already in the link, after the #, which never leaves your device:
#text=— the text to work on#html=— the HTML
Example: https://mygadgets.ink/tools/html-minifier/#text=...&html=... · also compressed gz fields and ?url=. How tool links work
Quick start: using HTML Minifier
- Paste your HTML or load the file above.
- Run the minifier and note the byte reduction.
- Render the output and compare it against the original page carefully.
- Look specifically at spacing between inline links, buttons, and words.
- Copy the minified markup into production, keeping your source version intact.
Minify the assets too: CSS Minifier and JS Minifier.
What minification removes
An HTML minifier reduces size by cutting:
- Comments — developer notes and commented-out sections.
- Whitespace between tags — the indentation that shows structure.
- Redundant attributes and quotes where the spec allows omitting them.
The rendered page is identical; only the transferred bytes shrink.
HTML minification is more delicate than CSS or JS
Here is the catch: in HTML, whitespace sometimes matters. Unlike CSS and JavaScript, where you can strip whitespace freely, HTML has cases where removing a space changes what the user sees:
- Between inline elements, a space is a visible gap. Collapsing it can push words together.
- Inside
<pre>and<textarea>, whitespace is preserved and significant — it must never be touched. - Around inline-block elements in CSS layouts, whitespace can affect spacing.
A good minifier is conservative about these cases. After minifying, glance at the page to confirm nothing shifted, especially text spacing.
How much it saves
HTML minification savings are usually smaller than for CSS or JavaScript, because HTML has less removable whitespace proportionally. The bigger win for HTML comes from server compression (gzip/Brotli), which crushes repetitive markup dramatically. Minify as a small extra gain on top of compression, not as the main strategy.
Where it fits
Minifying HTML is part of a pre-deploy routine alongside CSS Minifier and JS Minifier. For static sites generated ahead of time, minify the output. For dynamic pages, ensure server compression is on first — that is the larger lever.
Common uses
- Shrink static pages before publishing.
- Trim large HTML documents and email templates.
- Squeeze extra bytes on high-traffic pages.