Quick answer
To minify HTML, paste your code into the HTML code box. Choose the options — Remove comments, Minify inline CSS & JS and Remove optional attribute quotes — and the Minified HTML appears with the original size, new size and percentage saved. Copy or download the result. Content inside <pre> and <textarea> is kept exactly as written. Everything runs in your browser.
- Removes:
- Comments, line breaks, indentation, extra spaces
- Inline code:
- Minifies <style> CSS and <script> JavaScript
- Optional:
- Remove safe attribute quotes
- Protected:
- pre, textarea, script and style whitespace
- Stats:
- Original size, minified size, percent saved
- Output:
- Copy or download
- Upload needed:
- No – runs in your browser
- Price:
- Free
HTML written for humans is full of characters browsers do not need: indentation that makes nesting readable, line breaks between tags, comments explaining sections, blank lines and spaces before closing brackets. On a typical page these add 10–30% to the file size. Every byte must travel over the network before the browser can start rendering, so smaller HTML means a faster first paint — especially on mobile connections and in regions with slower internet.
Our HTML minifier removes that overhead safely. It collapses whitespace between tags, removes comments (keeping conditional comments), trims spaces inside tags and can minify the CSS inside <style> blocks and the JavaScript inside <script> blocks. An optional setting removes quotes around attribute values where HTML allows it.
Whitespace matters in a few places, and the minifier knows them: text inside <pre> and <textarea> is preserved exactly, and scripts and styles are only changed by their own minifiers. The result works the same as your original — just smaller.
Use it for static pages, landing pages, email templates, HTML snippets for widgets and anywhere you deliver hand-written HTML. All processing happens in your browser, so your code stays private.
How to minify HTML – step by step
- 1 Paste your HTMLPaste a full document or a snippet into the HTML code box.
- 2 Choose optionsKeep Remove comments on, turn on Minify inline CSS & JS for extra savings, and Remove optional quotes for maximum compression.
- 3 Review the resultThe minified HTML appears with the size before, size after and percentage saved.
- 4 Test itOpen the minified page in a browser to confirm it looks and works the same.
- 5 Copy or downloadCopy the code or download it and deploy it to your site.
Why use this HTML minifier?
Safe whitespace removal
Collapses spaces without merging words.
Comment removal
Strips developer comments, keeps conditional comments.
Inline CSS and JS
Minifies style and script blocks too.
Protected blocks
pre and textarea content is untouched.
Clear savings
Shows bytes and percentage saved.
Private and free
Runs in your browser, no sign-up.
What HTML minification removes
| Removed | Example | Safe? |
|---|---|---|
| Indentation and line breaks | Spaces at the start of lines | Yes |
| Whitespace between tags | </li> <li> | Yes, in almost all layouts |
| HTML comments | <!-- header --> | Yes (conditional comments kept) |
| Spaces inside tags | <div class="a" > | Yes |
| Optional attribute quotes | class="card" → class=card | Yes for simple values |
| Inline CSS/JS whitespace | Spaces in <style> and <script> | Yes, via proper minifiers |
How much faster will my page be?
Savings depend on how the HTML was written. Neatly indented, commented templates often shrink by 15–30%; already compact HTML may only save a few percent. When your server uses gzip or Brotli compression, the transferred difference is smaller, because compression already shrinks repeated whitespace very well — but minified files still compress slightly better and are faster for the browser to parse. Minification is one of several small improvements that add up: compress images, minify CSS and JS, cache static files and use a CDN. Check whether your server compresses responses with our HTTP Headers Checker.
The whitespace gotcha: inline elements
Browsers treat whitespace between inline elements (links, spans, buttons, inline-block elements) as a visible space. In a navigation menu built with inline-block items, removing the whitespace between them removes the small gaps, which can slightly change spacing. Most modern layouts use flexbox or grid, where this does not matter. If you notice a layout change after minifying, add the spacing with CSS margins or gap instead of relying on whitespace in the HTML — which is better practice anyway.
When not to minify HTML by hand
If your site runs on WordPress, Shopify, Wix or another CMS, the HTML is generated on every request, so minifying a copy here does not help. Use a caching or optimisation plugin instead — such as LiteSpeed Cache, WP Rocket or Autoptimize on WordPress — which minifies output automatically. Frameworks and build tools (Vite, Webpack, Next.js, Laravel Mix) also minify during production builds. This online tool is ideal for static HTML files, email templates, landing pages, embeddable widgets and quick checks.
Minifying email templates
HTML emails are often large, and Gmail clips messages larger than about 102 KB, hiding the rest behind a "View entire message" link — which can hide your unsubscribe link and tracking pixel. Minifying the template is an easy way to stay under that limit. Keep the option to minify inline CSS on, but be careful: email clients rely heavily on inline styles and tables, so test in your email platform's preview after minifying.
Minifying HTML for widgets and embeds
Many people write small HTML snippets that other sites embed: newsletter sign-up forms, booking buttons, review badges, pricing tables or the code for a hit counter. When such a snippet is pasted into page builders, CMS fields or email platforms, line breaks and indentation can cause trouble — some editors add paragraph tags around each line, others refuse long multi-line code, and every extra character counts when the snippet is loaded on thousands of pages. Minifying the snippet into a single compact line makes it easier to paste, less likely to be altered by editors and faster to load. Keep a commented, readable version for yourself and share the minified one with users.
Keep the readable original
Minified code is hard to read and edit. Always keep the original, formatted HTML in your project or version control, and treat the minified file as a build output you regenerate after every change. Never edit minified code directly — make changes in the source and minify again.
Complete front-end optimisation
After the HTML, minify your stylesheets with the CSS Minifier and your scripts with the JS Minifier, shrink images with the Image Compressor and serve modern formats via the Image Converter. Then measure the result with the performance score in our Website Screenshot tool, and check on-page SEO with the SEO Report.
Does minification affect SEO?
Minification does not change content, headings, links or meta tags, so search engines read the page exactly as before. It can help indirectly by improving loading speed, which is part of page experience. Make sure you do not accidentally remove important comments that a tool relies on, such as verification snippets placed in comments — rare, but worth checking.
Privacy
The minifier runs in JavaScript inside your browser tab. Your HTML — which may contain unreleased designs, internal links or client content — is never uploaded.
Troubleshooting
- Small gaps between menu items disappeared. Inline-block whitespace was removed; use CSS gap or margins.
- An error appears for inline JavaScript. The script contains a syntax error; fix it or turn off inline minification.
- Template tags broke. Server-side templates (Blade, Liquid, PHP) can confuse the minifier; minify the rendered HTML, not the template source.
- Text in a code block changed. Use <pre> for preformatted text so whitespace is preserved.
Frequently asked questions
What does an HTML minifier do?
It removes unnecessary characters such as whitespace and comments to make HTML smaller without changing how it works.
Is minified HTML safe to use?
Yes. It renders the same; test pages with inline-block layouts after minifying.
How much can HTML minification save?
Typically 10–30% of the HTML size, depending on formatting and comments.
Does it minify inline CSS and JavaScript?
Yes, when Minify inline CSS & JS is enabled.
Will my pre and textarea content change?
No. Whitespace inside pre and textarea is preserved.
Does HTML minification help SEO?
Indirectly, by making pages load faster. Content is unchanged.
Should I minify WordPress HTML here?
No. Use a caching or optimisation plugin, because WordPress generates HTML on each request.
Is my code uploaded?
No. Minification runs in your browser.
Can I unminify HTML?
Formatting tools can re-indent it, but comments removed are lost. Keep your original file.
Is the HTML minifier free?
Yes. No sign-up required.
Does Gmail clip large emails?
Yes, messages over about 102 KB are clipped. Minifying templates helps stay under the limit.
Does minifying remove my meta tags?
No. Meta tags, links, headings and all content stay in place; only unnecessary whitespace and comments are removed.
Can I minify a whole website at once?
This tool minifies one file or snippet at a time. For whole sites, use your build tool or a caching plugin.
Last updated November 21, 2026 · Written and tested by the SmallEasyTools team.