100% local — your data never leaves your browser

HTML Minifier — A Lighter Page, Same Layout

Strip the whitespace from HTML. Attribute values and the spaces between inline elements are kept, so the page gets smaller and looks the same.

Instant Private Zero cookies

HTML input

HTML output

What this tool does

Readable HTML becomes the smallest HTML that renders identically.

<div>
  <p>  Hello  </p>
</div>
<div><p> Hello </p></div>

Runs of whitespace become one space, the whitespace between block elements goes, and comments go — except the conditional ones, which are instructions to an old browser rather than notes to a reader.

The space between two inline elements is content

<span>a</span> <span>b</span>
<span>a</span> <span>b</span>

Nothing to strip there: that space is rendered, and removing it turns “a b” into “ab”. It used to be removed, which made the page different rather than smaller — a real defect, found while writing this page and fixed. Around a block element the same space renders as nothing, so it goes:

<div>a</div>   <div>b</div>
<div>a</div><div>b</div>

Attribute values are not layout

<input value="a  b">
<input value="a  b">

The two spaces stay. They used to be collapsed into one, because the whitespace pass ran straight through the attributes — and the value a form submits, the text of a title, the content of an alt are data, not indentation. Quoted values are set aside before the collapse and put back untouched.

What it never enters

  • <pre> and <textarea>. Displayed or submitted exactly as written.
  • <script> and <style>. Their content is JavaScript and CSS; the minifiers for those are separate tools on this site, and running them is your decision, not a side effect of this one.
  • Conditional comments. <!--[if IE]>…<![endif]--> is read by a browser, so it stays.

One limit worth knowing: a protected region ends at its closing tag, found by pattern. A literal </script> inside a JavaScript string therefore ends it too early. Catching that case properly takes a full HTML parser, which is a different tool from a whitespace minifier.

Private by design

Everything runs locally in your browser with JavaScript. Your data is never uploaded, which makes the tool safe for sensitive content, and it keeps working offline.

Frequently asked questions

Does it change what my page looks like?
No, and that was worth fixing. The space between two inline elements is rendered: `<span>a</span> <span>b</span>` reads “a b”, and removing that space used to give you “ab”. It is now kept when both sides are inline, and removed around block elements, where it renders as nothing. Smaller, not different.
Are my attribute values touched?
Not any more. The whitespace collapse used to run through them, so `<input value="a b">` came back with one space — and the value a form submits is not a matter of layout. `title`, `alt`, `data-*` and the rest had the same problem. Quoted values are now set aside before the collapse and put back exactly as they were.
What is left alone entirely?
`<pre>` and `<textarea>`, whose whitespace is displayed or submitted as written; `<script>` and `<style>`, whose content is not HTML; and conditional comments (`<!--[if IE]>`), which are instructions rather than notes. Ordinary comments are removed. One known limit: a literal `</script>` inside a JavaScript string ends the protected region too early — finding it properly needs a real HTML parser.
` inside a JavaScript string ends the protected region too early — finding it properly needs a real HTML parser."}}]}

Related converters