How to use the HTML minifier and beautifier
- Minify: paste your HTML and choose what to remove. By default the tool drops comments, collapses runs of whitespace and compacts the CSS inside
<style>blocks. The counters show the bytes saved. - Beautify: switch to this tab to re-indent messy or already-minified HTML so that it is readable, using 2 spaces, 4 spaces or a tab.
- Copy the result, or press Use result as input to chain the steps, for example to beautify and then edit.
Everything runs locally in your browser, so private templates and unreleased pages are never uploaded.
What minification does and does not touch
| Content | Minify | Why |
|---|---|---|
| HTML comments | Removed (conditional comments kept) | They are only for developers |
| Whitespace between tags that includes a line break | Removed | Indentation and newlines have no visual effect between block elements |
| Runs of spaces in text | Collapsed to one | The browser already collapses them when rendering |
| CSS in <style> | Comments removed, spaces compacted | Safe for standard CSS |
| JavaScript in <script> | Left alone, or lines trimmed if you choose | Real JS minifying needs a parser; this tool avoids breaking code |
| <pre> and <textarea> | Never changed | Their whitespace is meaningful |
| Attribute values | Kept, unless you remove optional quotes | Quotes are needed for values with spaces |
Why minify HTML at all?
Smaller pages download faster, which helps people on slow mobile connections and gives a small boost to Core Web Vitals such as Largest Contentful Paint. On a typical hand-written page, stripping comments and indentation saves 10% to 30% of the raw size. Once the server compresses the file with gzip or Brotli, which already squeezes repeated whitespace, the real saving is smaller, often 2% to 8%, so minifying HTML is a minor gain next to compressing images, trimming scripts and caching.
Minification is worth doing as a last step before publishing, on the output of a build, and not on the file you edit. Keep the readable source, minify a copy and deploy that. The beautifier does the opposite and is useful when you receive a one-line page from a plugin, an email template or a "view source" and need to make sense of its structure.
saved bytes = original bytes − minified bytes saving % = saved ÷ original × 100
Worked example
Press Try sample. The input is a small page of about 560 bytes with indented tags, a comment, a CSS comment, a <pre> block and a short script. With the default options:
- The
<!-- page styles -->comment disappears. - The newlines and indentation between tags are removed, so
<head>,<meta>and<title>join up. - The heading text
Hello, worldbecomesHello, worldwith single spaces. - The CSS becomes
body{margin:0;font-family:sans-serif}.card{padding:16px}, with the comment gone. - The
<pre>block, with its precise spacing, is untouched, and so is the script, with its line comment.
The saving is nearly 30% of the size. Switch to Beautify and the minified version returns to a tidy tree with one tag per line, each level indented.
Tips and safe practice
- Keep inline spaces:
<b>a</b> <i>b</i>needs its space. The default mode keeps a single space where it sits on one line, and only the aggressive mode removes it. - Test after minifying: open the result in a browser and compare it with the original, especially if the page has inline-block buttons or navigation items.
- Do not minify templates with logic: Jinja, PHP, Liquid and similar tags are not HTML, and the tool may reflow them. Minify the rendered output instead.
- Do not strip important comments: licence headers and conditional comments for old Internet Explorer should be kept; the tool keeps conditional comments.
- Use a build tool for JavaScript: proper JS minification needs a parser, such as the ones in common bundlers.
Accuracy and limits
This is a text-based minifier and beautifier. It does not parse HTML into a full document tree, check that tags are balanced or fix invalid markup. Beautify puts each tag and each run of text on its own line, so inline elements such as <b> or <a> inside a sentence are split across lines. Browsers render this the same way, apart from a single space around those lines, but it is not ideal for reading long paragraphs. Code in <script> is re-indented but never rewritten. Do not use the output for security purposes, as it does not sanitise HTML.
Frequently asked questions
Will minifying HTML change how my page looks?
In the default mode it should not, because it removes only comments and whitespace that browsers ignore or collapse. Test any page that depends on spaces between inline elements, and avoid the aggressive option on those.
Does the tool minify JavaScript?
Not fully. Proper JavaScript minification needs a parser. The tool can safely trim leading and trailing spaces on each script line, and otherwise leaves scripts as written.
How much smaller will my HTML be?
Typically 10% to 30% in raw size. After gzip or Brotli compression on your server, the difference shrinks to a few percent.
Is HTML minification good for SEO?
Slightly. Smaller pages load faster, and speed is a ranking signal, but the effect is small. Content, structure and links matter far more.
Can it beautify HTML that is all on one line?
Yes. Use the Beautify tab. It splits the tags onto separate lines and indents each level, with your choice of 2 spaces, 4 spaces or a tab.