HTML Minifier

Minify HTML by stripping comments and collapsing whitespace, while preserving inline spacing and the contents of pre, textarea, script, and style. Runs in your browser.

Minified 199153 bytes (23.1% smaller)

<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <p>Hello <strong>world</strong></p> <pre>  preformatted
    stays </pre> </body> </html>

Strips comments and collapses whitespace to a single space — preserving meaningful spacing between inline elements, and leaving <pre>, <textarea>, <script>, and <style> contents untouched.

About this tool

HTML is full of whitespace that browsers ignore — indentation, blank lines, gaps between tags — and removing it shrinks the page without changing what renders. This minifier does that conservatively. It strips HTML comments and collapses every run of whitespace down to a single space, but it does not delete spaces between elements entirely, because the space between two inline elements (like <strong> or <a>) is meaningful and removing it would visibly run words together. It also fully protects the contents of elements where whitespace is significant or is not markup: <pre> and <textarea> (where spaces and newlines are rendered literally) and <script> and <style> (where collapsing could break code). The result is smaller HTML that looks identical. For the last few percent — removing optional tags and quotes, minifying inline CSS/JS — use a build-time minifier; this is a safe, instant pass that runs entirely in your browser.

How to use it

  • Paste your HTML.
  • Read the minified output and the byte savings.
  • Copy it into your page or template.
  • Note that pre/textarea/script/style content and inline spacing are preserved.

Frequently asked questions

Will minifying change how my page looks?
No. It only removes whitespace the browser already ignores and HTML comments. Crucially it keeps a single space between inline elements (so words do not merge) and leaves whitespace-sensitive elements untouched, so the rendered output is identical.
Why keep a space between tags instead of removing it?
Because for inline elements that space is rendered. "<span>a</span> <span>b</span>" shows "a b", but removing the space shows "ab". Aggressive minifiers that strip it can subtly break layouts, so this tool collapses to one space rather than deleting it.
What about <pre>, <textarea>, <script>, and <style>?
Their contents are protected and copied verbatim. In <pre> and <textarea> whitespace is visible to the user; in <script> and <style> collapsing it could change or break code. So none of them are altered.
Does it remove HTML comments?
Yes, standard <!-- ... --> comments are stripped, including IE conditional comments. If you rely on conditional comments for very old browsers, review the output before using it.
How much smaller will my HTML get?
It depends on how much indentation and how many comments the source has — typically a meaningful but modest reduction. Combined with gzip/brotli compression on the server, the win on the wire is smaller still, since compression already handles repetitive whitespace well.
Is my HTML uploaded?
No. Minification runs entirely in your browser with no network request.

Related tools