HTML Minifier
Minify HTML code by removing comments, collapsing whitespace, and stripping redundant attributes.
- Free
- No account
- Runs in your browser
- Nothing uploaded
Paste HTML and click Minify — removes comments, collapses whitespace, and strips redundant attributes. Runs entirely in your browser.
Runs entirely in your browser — your input is never uploaded, logged, or stored.Privacy policy
What is HTML Minifier?
HTML minification removes unnecessary characters from HTML source code without changing how the page renders or functions. The browser ignores most whitespace between elements, so removing it produces identical visual output with a smaller file size. Typical minification reduces HTML by 10–30%, which improves load times especially on slow connections.
This tool applies safe, reversible minification rules that preserve the document's structure and behavior: • Remove HTML comments — comments add no rendering value (conditional IE comments are preserved). • Collapse whitespace — multiple spaces and line breaks between tags become a single space. • Remove redundant attributes — type="text/javascript" and type="text/css" are defaults in HTML5. • Collapse boolean attributes — readonly="readonly" becomes readonly.
Whitespace-sensitive content inside <pre> and <textarea> elements is preserved — minifying these would break their formatting. Inline <script> and <style> content is left untouched to avoid breaking template literals or complex CSS.
All minification runs in your browser. No HTML is sent to any server.
HTML minification follows the WHATWG HTML specification for optional tags and safe transformations:
1. Comment removal: Strips <!-- ... --> except conditional comments (<!--[if ... ]>) which are required for IE compatibility.
2. Whitespace collapse: Replaces sequences of spaces, tabs, and newlines between tags with a single space. Browsers treat inter-element whitespace as a single space in rendering, so this is visually identical.
3. Redundant attribute removal: type="text/javascript" on <script> and type="text/css" on <link rel="stylesheet"> are the default in HTML5 and can be safely removed.
4. Boolean attribute collapse: Attributes like readonly, disabled, and autofocus that accept any value (including empty string) can be written without the ="value" part.
All transformations are spec-safe and produce identical DOM output when re-parsed.
Worked examples
- Minify "<div> <p> Hello </p> </div>" → "<div><p>Hello</p></div>" — whitespace between tags collapsed.
- Minify "<!-- header -->\n<div>content</div>\n<!-- footer -->" → "<div>content</div>" — comments removed.
- Minify "<script type=\"text/javascript\">alert(1)</script>" → "<script>alert(1)</script>" — redundant type attribute removed.
- Minify "<input readonly=\"readonly\" disabled=\"disabled\">" → "<input readonly disabled>" — boolean attributes collapsed.
- Minify "<p>First</p>\n<p>Second</p>" → "<p>First</p><p>Second</p>" — whitespace between tags collapsed.
How to use HTML Minifier
- Paste your HTML code in the input area.
- Toggle options: remove comments, collapse whitespace, remove redundant attributes, collapse booleans.
- Click Minify to see the minified output and size reduction percentage.
- Copy the minified HTML or download it as a file.
Common errors
- Minified HTML looks broken in a textarea — the textarea itself contains the HTML, not renders it. Copy the output and paste it into an HTML file to verify it renders correctly.
- Whitespace inside <pre> or <code> is changed — this tool preserves whitespace in pre, textarea, and code elements. If you see changes, the content might not be properly wrapped in these tags.
- Comments I need were removed — conditional IE comments (<!--[if IE]>) are preserved. Regular HTML comments are removed; if you need them, disable the remove comments option.
- Size reduction is smaller than expected — inline CSS and JavaScript are not minified by this tool. Use a dedicated CSS/JS minifier for those. HTML minification typically reduces size by 10–30%.
FAQ
Is minified HTML safe to use in production?
Yes. All transformations are spec-safe and produce identical DOM output when re-parsed by the browser. The visual rendering and functionality are unchanged. This is the same process used by build tools like Webpack, Vite, and Next.js.
Does minification affect SEO or accessibility?
No. Search engines and screen readers parse the rendered DOM, not the raw HTML source. Minification removes comments and whitespace, not content. Accessibility attributes like aria-label and role are preserved.
What's the difference between minification and compression?
Minification reduces file size by removing unnecessary characters (comments, whitespace). Compression (gzip, brotli) reduces transfer size by encoding repeated patterns. Both can be used together — minify first, then compress. Compression typically achieves 60–80% additional reduction on minified HTML.
Why not just use gzip compression instead?
Use both. Minification reduces the source size before compression, which makes compression more effective. A 100KB HTML file minified to 70KB then gzipped to 15KB is smaller than the same 100KB file gzipped to 20KB. The minification step is cheap and compounds with compression.
Can I undo minification?
Not automatically. Minification is a one-way transformation — the original formatting is lost. Always keep the unminified source in your version control and minify only for production builds.
Related tools
Prefer AllUtil on Google
One click adds AllUtil to your Google preferences. You'll see our tools highlighted with a Preferred badge in Search and AI answers.