HTML Minifier
Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.
Last reviewed by the Radiatus Cloud team
Need this built for your product?
We design, build & host secure software & APIs.
HTML whitespace is not always insignificant
Minifying HTML is riskier than minifying CSS or JavaScript, because whitespace in HTML sometimes renders. Between block-level elements it collapses to nothing visible and can be removed freely. Between inline elements it renders as a single space, so removing it joins words together: <span>one</span> <span>two</span> becomes onetwo if the space is stripped. This is the single most common way an aggressive minifier breaks a page.
Inside <pre> and <textarea>, and anywhere white-space: pre applies, every character is literal. Touching that whitespace changes what the user sees. A safe minifier must know about these elements and leave their contents completely alone.
What is safe to remove
Comments, except conditional comments if you still support very old Internet Explorer. Leading and trailing whitespace inside block elements. Redundant closing tags that HTML5 makes optional, though removing them hurts readability for little gain. Quotes around attribute values that contain no spaces or special characters, which saves very few bytes and is rarely worth the reduced clarity.
Compression does most of the work
As with CSS, gzip and Brotli already handle repetitive markup extremely well. HTML is highly repetitive, so it compresses exceptionally efficiently: a document can commonly shrink by 75 to 85 percent through compression alone. Minifying before compression adds a comparatively modest further saving. Verify compression is enabled before spending effort on minification.
Server-rendered pages
For pages generated by a template engine, minifying the output on every request costs CPU on every request. It is usually better to keep templates tidy, enable compression, and skip HTML minification entirely. Minification makes most sense for static files produced once at build time.
Local processing
Everything runs in your browser, so pages containing customer data, internal endpoints or unreleased copy are never transmitted.
Related tools
- JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
- JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
- Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
- CSS Minifier — Minify CSS by stripping comments and whitespace safely. Runs in your browser with no upload, and reports the byte saving before and after gzip.
Frequently Asked Questions
Can minifying HTML break my page?
Yes, if it is done carelessly. Whitespace between inline elements renders as a visible space, so removing it joins words together. Content inside pre and textarea is literal. A safe minifier must recognise both cases and leave them alone.
How much does HTML minification save?
Usually 5 to 20 percent of raw bytes. After gzip or Brotli the additional benefit is modest, because HTML is highly repetitive and compresses very well on its own, often by 75 to 85 percent.
Should I minify server-rendered HTML?
Usually not. Minifying on every request costs CPU on every request for a small marginal gain over compression. Keep templates tidy, enable compression, and reserve minification for static files built once.
Is it safe to remove quotes around attributes?
Only when the value contains no spaces, quotes, equals signs or angle brackets. The saving is a couple of bytes per attribute and the readability cost is real, so it is rarely a good trade.
What about conditional comments?
Comments of the form targeting old Internet Explorer are functional, not decorative, and removing them changes behaviour in those browsers. Unless you have dropped support for them entirely, preserve conditional comments.
Privacy & Security
Processing is client-side.
How to Use
Paste your HTML and click Minify to strip whitespace/comments.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.
Related Tools
JSON Formatter
DeveloperFormat and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
JSON Validator
DeveloperValidate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
Regex Tester
DeveloperTest regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.