Modern Niche World MNW

HTML Minifier

Paste HTML and get a smaller copy with comments and extra whitespace removed, while the parts where spacing matters stay exactly as written.

Remove
0 bytes

Paste HTML to see it minified.

Your HTML stays on your device: nothing is sent or saved. Up to 5 MB.

Smaller HTML, with nothing that matters changed

Indentation, line breaks and comments make HTML easy to work on, but visitors download every one of those bytes. This minifier removes them carefully. It works on the rules browsers use to read HTML, not on guesses, so it knows where a space can show on screen and where it can’t, and it leaves alone anything it isn’t sure about.

How to use it

  1. Paste your HTML into the left box. The minified copy appears as you type.
  2. Choose what to remove. All three options are on to start with.
  3. Check the size before and after, and any warnings under it.
  4. Copy the result, or download it as an .html file.

What the options do

  • Comments removes <!-- notes -->. Conditional comments and server-side includes stay, because they do a job.
  • Extra whitespace shortens each run of spaces, tabs and line breaks in text to one space, and removes whitespace in the head and around the html and body tags, where it never shows.
  • Spaces around block elements also removes the space next to elements such as div, p, li, td and br. Browsers don’t show it unless your CSS lays those elements out side by side.

What it never changes

  • Attribute values and quotes: the spaces between attributes are tidied, nothing else.
  • The content of pre, textarea, script and style.
  • A no-break space, typed or written as &nbsp;.

Good practice

  • Keep the readable file as your working copy, and minify a fresh copy each time you publish.
  • Open the minified page in a browser at phone and desktop widths before you upload it, and compare it with the original side by side.
  • Read any warnings. An unclosed comment or tag usually means a mistake in the original that browsers are already hiding.

Good to know

  • Minify the final HTML, not a template: template tags inside HTML can be read in ways the template engine didn’t expect.
  • Your server may already compress pages with gzip or Brotli. Minifying still helps, but the saving over the network is smaller than the one shown here.
  • Images are often the heaviest part of a page. Shrink them with the Image Compressor, and make a site icon with the Favicon Generator.

Frequently asked questions

Will minifying change how my page looks?
It shouldn’t. The tool removes only comments and whitespace a browser doesn’t show, and keeps one space wherever words or inline elements meet. Two cases to know: if your CSS shows block elements such as li or div side by side, turn off “Spaces around block elements”; and an element other than pre or textarea styled with white-space: pre will lose its line breaks.
What does it leave alone?
Attribute values and their quotes, everything inside pre, textarea, script and style, the conditional comments written for old versions of Internet Explorer, and server-side include directives. It doesn’t minify the CSS or JavaScript inside the page; a CSS or JavaScript minifier does that.
How much smaller will my HTML get?
That depends on how it was written. Hand-indented pages with many comments shrink the most; HTML that a build tool has already compressed may barely change. The tool shows the exact size before and after.
Is my HTML uploaded?
No. The minifying happens in this page, on your device. Nothing is sent or saved, so you can paste pages that aren’t public yet.