HTML Minifier

Paste HTML and the minified version appears below, with the bytes saved. It removes comments and the whitespace the browser ignores, and keeps every space that shows on the page.

How it works

In HTML, whitespace between two block elements, such as two paragraphs, is invisible. Whitespace between two inline elements, such as two links, shows as a space. The minifier knows which elements are which, so it removes the first kind and turns the second kind into a single space.

Comments are removed, except Internet Explorer conditional comments. Content inside pre and textarea is copied exactly, because there every space shows. Inline style blocks go through the same careful CSS minifier as the CSS Minifier tool. Script content is only trimmed at the ends.

Attribute values are never changed, and no tags are removed. The work happens on this page, and your HTML is not uploaded.

How to use it

  1. 1 Paste your HTML into the first box.
  2. 2 The minified HTML appears in the second box as you type, with the size before and after.
  3. 3 Press Copy result, or download it as a .html file.

Good to know

  • Keep your readable HTML as the source and minify a copy. The HTML Formatter can lay out minified HTML again, but it cannot bring back the comments.
  • If an element shows whitespace because of CSS, such as white-space: pre on a div, use a pre element instead. The minifier cannot see your CSS rules.
  • Most servers already compress HTML with gzip or Brotli. Minifying still helps, but the saving on the wire is smaller than the saving shown here.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Which spaces in HTML can go: minifying a menu and a paragraph

Take a short piece of HTML. It starts with a comment, <!-- nav -->. Then comes a list with the class "menu" and two items. The first item is a link to the home page. The second is a link that says "Tea", then the word "and", then "cake" in bold. After the list is a paragraph that says "Open daily from 9.", written over three lines with extra spaces, and with "daily" in italics. Last is a pre element holding two indented lines. With its line breaks and indents, the snippet is 188 bytes.

The comment goes first, because the browser never shows it. Then the minifier looks at each run of whitespace and asks one question: is it next to a block element? The line break between the comment and the ul, the indents before each li, and the line break before the closing tag of the list are all next to blocks. A browser ignores whitespace there, so the minifier removes it. The line break after the opening p tag and the one before its closing tag go for the same reason.

Other spaces stay. Between the "Tea" link and the word "and" there is a space, and it shows on the page. Remove it and the reader sees "Teaand". The minifier keeps it. Inside the paragraph, "Open daily" has three spaces, and a line break and an indent sit before "from". A browser shows any run of whitespace in normal text as one space, so the minifier writes one space in each place, and the page looks the same. The pre element is copied exactly, indents and line break included, because a pre shows every space. The result is 158 bytes, about 16% smaller, and the page looks the same.

The hard part of an HTML minifier is not removing spaces. It is knowing which ones are safe to remove. A minifier that removes all whitespace between tags would join "Tea" and "and". One that collapses every run of whitespace would break a pre block or the text in a textarea. This tool knows which HTML elements are blocks and which are inline, and it treats pre, textarea, script and style as special. That is why the output can be trusted without checking every line.

There are limits. The minifier cannot see your CSS, so if you set white-space: pre on a div, it will still collapse the spaces inside that div. It does not minify inline JavaScript, only trims it, and it does not remove optional closing tags or attribute quotes. It also does not check your HTML: an unclosed tag stays unclosed. And if your server already compresses pages with gzip or Brotli, the saving on the wire is smaller than the saving on disk shown here.

Frequently asked questions

Will minifying change how my page looks?

For normal HTML it should not. The minifier keeps one space wherever a space can show, such as between two links or between a word and a bold word. It only removes whitespace next to block elements, where the browser ignores it anyway. The one exception is an element that you made whitespace-sensitive with CSS, which the minifier cannot know about.

Does it minify inline JavaScript?

No. Script content is only trimmed at the start and end. Minifying JavaScript safely needs a full JavaScript parser, and a mistake there breaks the page. Inline style blocks are minified, with the same rules as the CSS Minifier.

Does it remove optional tags or attribute quotes?

No. HTML lets you leave out some closing tags and some quotes, but removing them saves little and makes the output harder to check. The minifier only tidies the space between attributes.

Are conditional comments kept?

Yes. Comments in the form <!--[if IE]> ... <![endif]--> are kept, because old versions of Internet Explorer read them. All other comments are removed.

Is my HTML sent to a server?

No. The minifier is JavaScript running on this page. Nothing you paste leaves your device.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.