HTML minifier

Paste your HTML and get a lighter version with comments and extra whitespace removed, plus the bytes and percentage saved. It is free and your code never leaves your browser.

How to use it

  1. Paste your HTML in the Your HTML box.
  2. Leave Remove HTML comments checked if you want comments gone.
  3. Read the sizes, then click Copy or Download to get the Minified HTML.

Complete guide to minifying HTML

What HTML minification is for

An HTML file written by hand or produced by a template engine is full of indentation, blank lines and comments that help developers but are useless to the browser. Removing them makes the document smaller, which helps most on pages with long markup such as listings, tables or generated content, and on slow mobile connections. Because the HTML is the first file a browser requests, trimming it also speeds up the moment the browser can start loading everything else. Keep the readable version as your source and publish the minified copy.

What gets removed and what is protected

Removed or reducedKept as it is
Line breaks and indentation between tagsContents of pre, textarea, script and style
Runs of spaces, reduced to a single spaceAttribute values and the doctype
Spaces around block elements such as div and pConditional comments for old Internet Explorer
HTML comments, if Remove HTML comments is checkedSpaces between inline elements, kept as one space

The last point is important. In <b>a</b> <i>b</i> the space is visible text, so removing it would glue two words together. The tool keeps one space there and removes the whitespace around block elements, where it has no visual effect. Inline style and script blocks are not minified; use the CSS minifier and the JavaScript minifier for those. Everything runs in your browser and nothing is sent.

Worked example

  1. Paste this into Your HTML and leave Remove HTML comments checked:

<div>
  <!-- note -->
  <p>Hello   <b>world</b>!</p>
</div>

  1. The Minified HTML is:

<div><p>Hello <b>world</b>!</p></div>

The Size panel shows 60 bytes before, 37 bytes after, 23 bytes saved, a 38.3% reduction. The three spaces after "Hello" became one, the comment disappeared and the line breaks vanished, but the space between "Hello" and the bold word was kept so the text still reads correctly.

Tips and common mistakes

  • Uncheck Remove HTML comments if your page depends on comments, for example markers read by a CMS or a server-side include. With it unchecked, comments are kept exactly.
  • Do not minify text you intend to keep editing. Minify a copy as the last step before publishing.
  • Do not expect the same savings on every page. A page with little indentation and no comments shrinks only a little, and most of the remaining size is the real content and the embedded scripts.
  • Turn on gzip or Brotli on the server too; compression works well on the repetitive text of HTML and stacks with minification.
  • Open the page and check key areas, such as pre-formatted blocks and spacing around links, after replacing the file.

Related tools

To reverse the process and read compact markup, use the HTML beautifier. To reduce the stylesheet and script that go with the page, see the CSS minifier and the JavaScript minifier.

Questions

Is my HTML sent to a server?

No. Everything runs in your browser and nothing is uploaded or stored.

What is kept exactly as it is?

The content of pre, textarea, script and style, plus attribute values and the doctype. Conditional comments for old Internet Explorer are also kept.

Will it remove the space between inline tags?

No. Spaces between inline elements such as links or bold text are reduced to one space, because removing them would join words on screen. Spaces around block elements like div or p are removed.

Does it minify the CSS and JavaScript inside the page?

No. Inline style and script blocks are preserved untouched. Use the CSS or JS minifier for those.