Free HTML Minifier
Shrink your HTML by removing comments and extra whitespace without breaking pre blocks, scripts or the spaces between inline words.
HTML Minifier: Shrink your HTML by removing comments and extra whitespace without breaking pre blocks, scripts or the spaces between inline words. It is free, needs no sign-up and runs in your browser. How to use it: 1) paste your HTML or load the sample; 2) choose which comments to keep and what else to minify; 3) click Minify, check the savings and download the file. The minifier uses the same tokenizer as our HTML formatter, so it knows the difference between text, tags, comments and raw script or style content. It then applies safe changes only.
How the HTML minifier works
The minifier uses the same tokenizer as our HTML formatter, so it knows the difference between text, tags, comments and raw script or style content. It then applies safe changes only.
- Comments: removed, while conditional comments and license comments that start with an exclamation mark can be kept.
- Whitespace: runs of spaces and line breaks collapse to one space. Whitespace next to block elements is removed. A single space between inline elements is kept so words do not join together.
- Protected content: pre and textarea are never touched. Script content is only trimmed unless you choose JavaScript minification.
- Inline CSS: style tags and style attributes are minified with our CSS minifier.
- JSON-LD: structured data scripts are compacted after checking the JSON is valid.
Optional extras
Removing attribute quotes is off by default because it saves little and some tools expect quotes. Inline JavaScript minification loads Terser on demand.
Formula
Savings = (original bytes minus minified bytes) divided by original bytes, times 100. Sizes are measured in UTF-8 bytes.
Limitations
Pages that use CSS white-space rules on ordinary elements can display differently after collapsing. Test before you deploy. Server compression with gzip or Brotli usually saves more than minification.
About this tool
The HTML Minifier is built and maintained by the Hayyat Networks team, a digital marketing, SEO and web development agency working with businesses in New York and Lahore since 2016. It is part of our free Website Development Tools collection.
- Last reviewed
- CostFree, no sign-up
- Where it runsRuns in your browser
- Checking resultsThe method and a worked example are shown above, so you can verify every result.
- PrivacyIt runs entirely in your browser: what you type stays on your device and is never sent to us.
Spotted a problem or have an idea? Tell us and we will review it.
Link to this tool
Free to share in your blog, course notes or resource list. Copy the link below:
<a href="https://hayyatnetworks.com/free-tools/website-tools/html-minifier/">HTML Minifier</a> by Hayyat NetworksHTML Minifier FAQs
Is it safe to minify HTML?
Yes, when done carefully. This minifier never touches pre, textarea or script content and keeps single spaces between inline elements. The main risk is CSS that relies on white-space: pre on normal elements, so test the minified page before publishing it.
How much smaller will my HTML get?
Typically 5% to 20%, depending on how many comments and indentation spaces your file has. Heavily commented templates save more. Enabling gzip or Brotli compression on your server usually cuts transfer size by 60% to 80% on top of that.
Should I remove HTML comments?
Usually yes, because visitors never see them and they can expose notes about your setup. Keep conditional comments if you support very old browsers, and keep license comments if a library requires them. Both are kept by default in this tool, and every other comment is removed.
Does it minify inline JavaScript?
Only if you tick the option. The tool then loads the Terser minifier from a public CDN and minifies each inline script. If Terser cannot load, for example because of a content blocker, scripts are simply trimmed so your page is never broken.
Want our experts to implement these improvements?
Get professional support from Hayyat Networks. Request a free consultation.
