Minify HTML
Shrink HTML by removing comments and collapsing whitespace. It runs entirely on your device — nothing is uploaded.
Example
Input
<div>
<!-- note -->
<p>Hi</p>
</div>
Output
<div><p>Hi</p></div>
How it works
The minifier strips comments and collapses runs of whitespace between tags to reduce file size while keeping the markup valid.
Good to know
Minify HTML takes a chunk of markup and squeezes it down by deleting HTML comments and collapsing the runs of spaces, tabs and line breaks that sit between tags. The result is byte-for-byte smaller markup that browsers parse identically, which makes it handy for front-end developers, email template builders and anyone shipping static pages who wants smaller files without changing how the page renders.
Reach for it when you are about to deploy: paste in a hand-written or generated HTML fragment, a full page, or an exported template, and copy the compact version into your build output or CMS. It is also useful for trimming inline HTML you embed inside JavaScript strings or email clients, where every saved byte counts and pretty indentation serves no purpose at runtime.
To read the output, compare it against the input: comments like <!-- note --> disappear entirely, and the gaps between elements shrink to nothing, so <div> <p>Hi</p> </div> becomes <div><p>Hi</p></div>. The tags, attributes and text content stay exactly as you wrote them — only the throwaway whitespace and comments are gone, so the markup remains valid.
One caveat worth knowing: collapsing whitespace can change rendering in places where spaces are significant. Watch out for the following before you minify blindly:
- Content inside <pre>, <textarea> and elements styled with white-space: pre, where line breaks and indentation are visible to users.
- Single spaces between inline elements (such as links or <span>s) that the browser would otherwise render as a visible gap.
- Conditional comments or comments your own tooling reads as instructions, since these are removed along with ordinary notes.
Frequently asked questions
Is my data uploaded anywhere?
No — everything runs in your browser. Your code never leaves your device, so it's safe for private work and runs offline once loaded.
Is this tool free?
Yes, completely free with no sign-up and no limits.
People also ask
How much smaller does minifying HTML actually make a file?
Savings vary with how much whitespace and how many comments the source contains, but typical hand-written or framework-generated pages shrink by roughly 10 to 30 percent before any server compression. Most of the real-world size win comes from gzip or Brotli on top, with minification adding a smaller incremental reduction.
Does minifying HTML break my page layout?
Usually not, because browsers ignore most whitespace between block-level tags. It can affect layout where spaces are meaningful, such as inside <pre> and <textarea> blocks or the single spaces between inline elements like links, so review those areas after minifying.
What is the difference between minifying and compressing HTML?
Minifying removes unnecessary characters from the source text itself (comments and extra whitespace), while compression like gzip or Brotli encodes the file at the transfer level and is undone by the browser. They are complementary: you can minify first and let the server compress the result.
Can I get my original formatting back after minifying?
Not exactly, because the removed comments and whitespace are discarded and not stored anywhere. You can re-indent minified markup with an HTML formatter or pretty-printer to make it readable again, but original comments will not return.
Is it safe to minify HTML that contains inline CSS and JavaScript?
The tag structure and the contents of <style> and <script> elements are preserved, so the code still runs. However, this tool focuses on HTML whitespace and comments rather than minifying the CSS or JS inside those blocks, which need dedicated minifiers for the deepest savings.
Should I minify HTML by hand or as part of a build step?
For one-off snippets, a browser tool like this is quick and requires no setup. For sites you deploy regularly, integrating a minifier into your build pipeline keeps the source readable while shipping compact output automatically.
Does minified HTML affect SEO?
Minification does not change the visible content, headings or links that search engines read, so it has no direct negative SEO effect. Smaller, faster-loading files can indirectly help by improving page performance metrics.
Related tools