HTML Minifier

Compress HTML markup by removing whitespace, comments, and optional tags.

Runs locallyInstantPrivate
Input
Output
Minified HTML appears here.

What This Tool Does

HTML minification reduces the byte size of your markup by stripping characters that browsers do not need to render the page correctly. This tool collapses runs of whitespace between tags, removes HTML comments, and — when you opt in — eliminates optional closing tags like </p> and </li> that the HTML5 specification defines as safe to omit. The result is semantically identical markup that downloads and parses faster, especially on large templates or CMS-generated pages.

How to Use

  1. Paste your HTML into the input panel on the left.
  2. Choose your options: enable Collapse whitespace to remove gaps between tags, toggle Keep HTML comments if your code relies on conditional comments, and enable Remove optional closing tags for maximum compression.
  3. The minified output appears instantly in the right panel.
  4. Copy the output or download it as a file for deployment.

Frequently Asked Questions

What is HTML minification?

Minification is the process of removing characters from source code that are not required for it to execute or render correctly. For HTML this means collapsing whitespace, deleting developer comments, and dropping tags the HTML5 parser allows you to omit. The resulting file is harder to read but functionally identical and smaller in byte size, which means faster transfer over the network and quicker initial page renders.

Will minifying HTML break my page?

Not for standard, well-formed HTML. The whitespace collapsing and comment removal performed here are safe operations on virtually all modern pages. Removing optional closing tags is also defined as valid by the HTML5 specification, so compliant parsers handle it without issue. The only edge case is JavaScript or CSS embedded directly in HTML using line-comment syntax — always test in a browser after minifying.

What is the difference between HTML minification and JavaScript uglification?

They target different languages with different rules. HTML minification removes markup whitespace and optional syntax that the HTML parser ignores. JavaScript uglification (sometimes called mangling) goes much further: it renames variables to single characters, removes unreachable code paths, and rewrites expressions for brevity. You typically run both — minify the HTML template and uglify any inline or bundled scripts separately using a build tool like esbuild or Terser.

Is it safe to remove optional closing tags?

Yes, for the tags the HTML5 spec explicitly lists as having optional end tags: </p>, </li>, </dt>, </dd>, </tr>, </th>, and </td>. All current browsers and HTML parsers handle these correctly. It is worth noting that some templating engines or XML-strict toolchains may reject this syntax — in those cases leave the option disabled.

Related tools