Home » Developer Tools » HTML Minifier

HTML Minifier

Paste HTML, shrink it instantly, and keep pre, script and style content exactly as it is.

Last updated 13 November 2026

Upload a file: or paste code below.
Input0 chars
Output0 chars
Original size0 B
Result size0 B
Change0%

Your code never leaves your browser. Everything runs locally on your device.

Large HTML files slow pages down and waste bandwidth. The BotixTech HTML Minifier removes comments and extra whitespace so your markup stays valid, loads faster, and is smaller to send, with no software to install.

It works fully in your browser, so your code is never uploaded to a server. Code inside pre, textarea, script and style blocks is left exactly as it is, so spacing that matters and code that must run keeps working after minifying.

How to Minify HTML

  1. Paste your HTML: paste code into the input editor or upload an HTML file.
  2. Choose your options: keep comment stripping and whitespace collapsing on, or turn either off.
  3. Minify it: press Minify HTML, or just wait a moment, because the result updates as you type.
  4. Copy or download: copy the result or download it as an HTML file for your site.

Why Use This HTML Minifier

What Is HTML Minification

HTML minification is the process of removing the parts of an HTML file that a browser does not need, while keeping the page working exactly as before. The parts that go are HTML comments, extra spaces, blank lines, and line breaks between tags. Tags, attributes, and text stay untouched, so the page looks and works the same after minifying. The only difference is the file is smaller, so it downloads faster and uses less bandwidth.

A browser does not need the spacing that humans need. When you write HTML, you add line breaks and indenting so you can read it. A browser reads tags, not line breaks, so all of that spacing is extra weight on every page load. Minifying takes it out. It does not change the meaning of the code, and it does not remove anything the page needs to display correctly.

What the Tool Removes and What It Keeps

This tool removes HTML comments and collapses runs of whitespace in normal text into single spaces. Whitespace only text between tags is removed. The doctype at the start of the document is kept. Attribute values are read with their quotes respected, so a value that contains a closing bracket, such as title="a > b", stays intact and the tag is not cut short.

Content inside pre, textarea, script, and style blocks is copied exactly, with no whitespace changes and no comment removal inside those blocks. That matters because spacing inside a pre block is part of the content, and code inside script and style blocks must keep working exactly as written. Spaces between words in normal text are kept as single spaces, so words never run together and the page still reads correctly.

Worked Example

Here is a small page run through the tool, with the exact numbers the tool shows:

Input, 102 characters:

<html> <head> <!-- a comment --> <title>Test</title> </head> <body> <p>Hello World</p> </body> </html>

Output, 76 characters:

<html><head><title>Test</title></head><body><p>Hello World</p></body></html>

The output is 26 characters shorter. 26 divided by 102 is 0.2549, so the file is about 25 percent smaller. The comment is gone, the spaces between tags are gone, and every tag, attribute, and word is still there.

The Load Sample button shows the same effect on a fuller page, with a doctype, a style block, a comment, and a pre block. That sample goes from 303 characters to 242 characters, 61 characters fewer, about 20 percent smaller. The style block and the spacing inside the pre block come through unchanged, and the title attribute with a closing bracket inside it survives intact.

Minification and Gzip

Minification and gzip do different jobs, and they stack. Minification removes comments and whitespace from the file itself. Gzip then compresses whatever is left when the server sends the file. Because gzip already squeezes out repeated spaces, the extra saving from minifying looks smaller after gzip than before it. That does not make minifying useless. A smaller file compresses to a smaller result, and pages served without gzip still benefit in full.

Measured with gzip on the sample above: the raw file goes from 303 characters to 242 characters, about 20 percent smaller. Compressed with gzip, the same two versions go from 227 bytes to 196 bytes, about 14 percent smaller. The tool shows raw sizes only. It does not show a gzip size, so use your server or hosting panel to check the compressed size your visitors actually download.

When Not to Minify

Do not minify a template that still has logic in it. If your HTML has Jinja, PHP, or Liquid tags, minify the finished page after the template has run, not the template itself. The minifier reads tags and text, and template tags can be damaged by comment stripping or whitespace collapsing.

Also keep a readable copy of every page you minify. Minified code is hard to read and hard to fix, so edit the original, then minify again when you publish. Never minify the only copy of a page. And do not minify while a page is still being built. Wait until the layout and content are settled, then minify once as a final step before the page goes live.

Minifier or Beautifier

A minifier and a beautifier do opposite jobs on the same code. A minifier makes HTML smaller and harder to read by removing comments and whitespace. A beautifier makes HTML bigger and easier to read by adding indenting and line breaks. Neither one changes what the page does.

Minify when a page is ready to publish and you want the smallest file. Beautify when you need to read or fix code that someone else minified. If the result here is hard to read later, open the HTML Beautifier to format it back into clean indented code. Keep the readable copy for editing and publish the minified copy.

What This Tool Does Not Do

This tool is honest about its limits, and they are worth knowing before you rely on it.

It does not minify the code inside style blocks. The CSS inside a style block is copied exactly, so shrink a stylesheet on its own with the CSS Minifier if that CSS needs to be smaller. It does not minify the code inside script blocks either. JavaScript inside a script block is copied exactly, so shrink it on its own with the JavaScript Minifier.

It has no compression levels, only the two checkboxes at the top of the page: strip HTML comments, and collapse whitespace. It shows raw sizes only, with no gzip figure. And it states no file size limit. Your HTML is minified in your browser, so a very large file may take a moment to process, and a whole site should be minified one page at a time.

When to Use It

Minifying pays off most on pages that real visitors load often. A production page that is minified sends fewer bytes on every visit, which helps on slow connections and on mobile data. Email templates are another good fit, since email HTML is often long and full of nested tables, and a smaller template is less likely to hit size limits.

It also helps with code from a content system or an export tool, which often adds extra whitespace and comments you do not need. And it helps with legacy pages that were written by hand years ago and never cleaned up. In every case, minify a copy, keep the original, and check that the page still looks and works the same after minifying.

Frequently Asked Questions

Will the HTML Minifier change code inside pre, script, or style blocks?

No. Content inside pre, textarea, script and style blocks is copied exactly, with no whitespace changes and no comment removal inside those blocks.

Does it remove HTML comments?

Yes, when comment stripping is on, which is the default. Turn the option off if you want to keep comments in the output.

What happens to whitespace in normal text?

Whitespace in normal text is collapsed to single spaces, and whitespace only text between tags is removed. This keeps the page readable by browsers while making the file smaller.

Is the doctype kept in the output?

Yes. The doctype at the start of your document is preserved in the minified output.

Is my code uploaded anywhere?

No. Minifying runs fully in your browser, so your code never leaves your device and is never stored on a server.

Can I minify a full HTML file?

Yes. Upload an HTML file, or paste a full page, and download the minified result as an HTML file.

Does it minify inline CSS or JavaScript?

No. Content inside style and script blocks is copied exactly, with no changes to the code inside them. To shrink CSS on its own, use the CSS Minifier, and to shrink JavaScript on its own, use the JavaScript Minifier.

How much smaller will my HTML get?

It depends on how many comments and how much extra whitespace your file has. The example on this page went from 102 characters to 76 characters, about 25 percent smaller, and the Load Sample page went from 303 characters to 242 characters, about 20 percent smaller. A file with long comments and deep indenting shrinks more than a file that is already tight.

Can I undo minification?

Yes. Open the HTML Beautifier and paste the minified code there. It formats the code back into clean indented lines that are easy to read and edit. Keep your original file too, so you always have a readable copy to work from.

Is there a file size limit?

The page does not state a size limit. Your HTML is minified in your browser, so a very large file may take a moment to process. For a whole site, minify one page at a time and check that each page still works after minifying.

↑