Developer Tools

HTML Minifier

Strip comments and redundant whitespace from HTML while protecting the content of pre, textarea, script and style tags.

Free to use No registration Mobile friendly Unlimited usage

What is the HTML Minifier?

HTML written for humans is full of things a browser does not need. Indentation showing nesting. Blank lines separating sections. Comments explaining what a block does. None of it affects rendering, and all of it is downloaded by every visitor.

Minifying removes it. On a typical page the saving is 15% to 25% before compression - modest on its own, but it applies to every request, and it costs nothing.

What gets removed

Comments disappear entirely. Worth pausing on: developer comments often contain more than intended. Notes about which server a feature is on, references to internal tickets, commented-out code showing an earlier approach, the name of a plugin and its version. None of that should be public. Stripping comments is as much a hygiene measure as a size one.

Conditional comments for old versions of Internet Explorer are preserved, since removing those would change behaviour on the browsers that still read them.

Whitespace is collapsed. Runs of spaces become one, and the gaps between tags are closed up. This is where most of the saving comes from in deeply nested markup.

Line breaks can be removed entirely with the third option, producing a single unbroken line. Maximum compression, zero readability.

What is deliberately protected

Four elements are left exactly as they were: <pre>, <textarea>, <script> and <style>.

The reason is that whitespace inside them is significant. Collapse the spaces in a <pre> block and your carefully formatted code sample turns into one line. Collapse them in a <textarea> and the default value the user sees changes. Remove line breaks inside a <script> and any JavaScript using single-line comments breaks, because everything after // on that line is now commented out - including the rest of your script.

This is the most common way a naive minifier breaks a page, and it is why those four elements are stashed aside before minification and restored afterwards.

The whitespace that does matter

One caveat worth understanding. In normal HTML flow, whitespace between inline elements is rendered as a space. If you write <span>one</span> <span>two</span> with a line break between them, the browser shows a gap. Collapse it and the words run together.

This affects inline elements - span, a, em, strong, img - not block-level ones. Modern layouts built with flexbox or grid are largely immune because those layout modes ignore the whitespace anyway. Older markup that relies on inline-block spacing is not. Check the visual result on a page or two before minifying a whole site.

Where it fits

For a site with a build step, minification belongs there. This tool is for the cases that do not have one: a landing page you are pasting into a CMS, an email template, a static file you are uploading by hand, or simply checking how much weight a page could shed before deciding whether it is worth automating.

Benefits of using the HTML Minifier

Protects what must not change

pre, textarea, script and style blocks are preserved exactly, so code samples and form defaults survive intact.

Strips revealing comments

Developer notes often name servers, tickets and plugin versions. Minifying removes them from the public page.

Shows the real saving

Before and after sizes with a percentage, so you can judge whether a build step is worth setting up.

No build tooling required

Useful for CMS blocks, email templates and hand-uploaded pages, where a compiler is not part of the workflow.

How to use the tool

Step 1

Paste the HTML you want to compress

Step 2

Leave remove comments and collapse whitespace on for a normal minify

Step 3

Add remove line breaks only if you want a single unbroken line

Step 4

Press Minify HTML and check the size reduction

Step 5

Test the result in a browser before publishing it

Popular use cases

  • Landing pages pasted into a CMS
  • HTML email templates
  • Static pages uploaded by hand
  • Reducing page weight for mobile
  • Stripping comments before publishing
  • Embedded widget markup
  • Measuring potential savings
  • Cleaning exported page source

Frequently asked questions

Not here. Script blocks are set aside before minification and restored untouched afterwards. This matters because removing line breaks inside JavaScript comments out everything following a // on that line - a classic way that naive minifiers destroy a page.

Typically 15% to 25% before gzip. Deeply nested, heavily indented markup saves most; already-compact pages save little. The counters show your actual figure. Remember that gzip on the server captures much of this saving anyway, so the incremental gain is smaller than the raw percentage suggests.

Ready to start using TU Web Tools?

Free, browser based utilities for developers, SEO professionals, students and businesses.

Free to use  •  Mobile friendly  •  No installation required