Free developer tool

HTML Minifier

Paste your HTML and the minifier removes comments and extra whitespace between tags to reduce file size without changing how the page looks.

Report a problem or suggest a fix for this tool

What is html minifier?

HTML pages often include indentation, line breaks and comments. Removing them reduces the bytes sent to visitors, which helps load times on slow connections.

This tool keeps the content of pre, textarea, script and style tags exactly as it is, so code blocks and scripts do not break.

How to use the html minifier

  1. Paste your HTML.
  2. Press Minify.
  3. Copy the result and test it in a browser.

How the html minifier works

Comments are removed, except conditional comments. Whitespace between tags is removed and runs of spaces are collapsed into one. Protected tags are set aside first and restored afterwards.

Worked example

A small block with a comment and indentation shrinks by almost half.

Common uses of the html minifier

  • Reducing the size of an email template or landing page.
  • Preparing static HTML for production.
  • Checking potential savings before using a build tool.
  • Cleaning up exported HTML from a page builder.
  • Making snippets smaller for embedding.

Tips and common mistakes

Whitespace between inline elements can matter. If words run together after minifying, put a space back.

Minify only for production. Keep readable source files in your project.

Background: what to know before you rely on it

HTML minification gives smaller gains than image or script optimization, but it is cheap and low risk. Where it matters most is on pages with large amounts of markup or repeated layout. The real win comes from combining it with compression on the server and caching. Be cautious with inline elements, because browsers treat a space between two inline elements as a visible space, and removing it can join words. Also watch for whitespace sensitive content such as pre blocks. Modern frameworks and static site generators usually minify automatically, so use this tool for hand written pages and quick checks.

Private, free and fast

This tool runs entirely in your browser. What you type or choose is not uploaded to a server and is not saved after you close the page, which keeps it fast and private. It is free to use as often as you like. See more in all developer tools, or browse the full list of tools.

Field by field guide

  • HTML code: Type or paste your text here. Use a new line for each entry where the label says so.

Change one field at a time to see how the result responds, and use the worked example above to check that you get the same answer.

Minifying HTML safely

Minifying removes comments and extra whitespace between tags, which reduces page size and speeds first paint a little.

Practical scenarios

  • Trimming a static landing page before upload.
  • Reducing the size of an email template that has a size limit.
  • Checking how much of a page is real markup and how much is whitespace.

Common mistakes

  • Minifying pages that contain pre or textarea content without checking them. Whitespace there is meaningful.
  • Removing conditional comments that older mail clients still read.
  • Skipping server compression. Gzip or Brotli gives larger savings than any minifier.

Smaller HTML pages

Most HTML savings come from whitespace and comments, usually 5 to 15 percent. Compression on the server removes much of the rest.

Expert tips

  • Minify as the last build step and test the result in a browser.
  • Keep whitespace inside pre and textarea.
  • Do not remove quotes around attributes if they contain spaces.
  • Inline critical CSS only when it is small.
  • Measure before and after with Lighthouse.

Small wins add up, but page speed depends more on images, scripts and server response.

Frequently asked questions

Is HTML minification safe?

Usually, but test the result. Spaces between inline elements can change spacing.

Will it break my scripts?

No. Script and style content is left as is.

How much will I save?

Often 10 to 30 percent before compression.

Does it fix errors in my HTML?

No.

Embed this tool on your website

Copy the code below and paste it into your page or blog post. The tool is free to embed, runs in the visitor's browser and needs no account. Please keep the credit link.

Related tools

Results are for information and education. For legal, financial, medical or security decisions, check with a qualified professional. Do not paste live secrets into any website.