Common mistakes people make with the HTML Minifier
Most bad results from the HTML Minifier are not faults in the tool. They are small slips: minifying a page that has a pre block in it, trusting a comment to sit safely between two words, or expecting a big saving from a page that was already tight. The tool itself uses exact rules, so when a result looks wrong, the input or the expectation is usually the cause, and each of the five mistakes below has a quick fix.
At a glance
Mistake 1: minifying a pre block or a textarea
This minifier collapses whitespace everywhere, including inside pre blocks and textareas, where spaces are part of the content. A pre block holding a few lines of code is 61 bytes as written and 49 bytes minified, so 12 bytes are saved, or 20% smaller, but the result is one line: <pre>function hello() { return "keep me"; }</pre>. The indentation and the line breaks that made the code readable are gone. A textarea behaves the same way: 43 bytes go to 35, and the spaces inside are collapsed to single spaces.
Mistake 2: leaving a comment between two words
A comment sitting between two words with no space on either side joins those words when it is removed. The line <p>Hello<!-- note -->world</p> is 30 bytes, and minified it becomes <p>Helloworld</p>, which is 17 bytes. The comment is gone, as it should be, but so is the gap between the words, because there never was a space there, only a comment. The fix is to put a space on one side of the comment before you minify, or to write the comment on its own line, between two tags, where its removal leaves nothing behind.
Mistake 3: a script string that looks like a comment
The tool removes anything between <!-- and -->, even when those characters sit inside a script. A line of JavaScript such as var s = "<!-- hi -->"; inside a script tag is 39 bytes, and minified it becomes var s = "";, which is 28 bytes. The text inside the string is gone, because the tool cannot tell a comment from a string that happens to contain the same characters. The fix is to avoid the characters <!-- inside script strings, or to minify the HTML and the script separately.
Mistake 4: expecting a big saving from a tight page
A page that is already written tightly has little left to remove. A short snippet that is 37 bytes as written comes out at 31 bytes, so only 6 bytes are saved, or 16% smaller. That is the tool working correctly: it found the 6 bytes of removable space and removed them, and there were no more to find. The same applies to the navigation list in the worked examples, which saved only 15%, or 22 bytes out of 147. A small percentage on a tight page is a sign the page was already in good shape, not a sign the tool missed something.
Mistake 5: pasting the output back in and expecting more
Minifying is a one-pass job. The sample output, at 64 bytes, pasted back into the tool comes out at 64 bytes again, with 0 saved, because there is nothing left to remove: no comments, no line breaks, no doubled spaces. If the percentage reads 0%, the job is done. Running the same page through a second time, or through a different minifier, will not find more, because the removable space is already gone.
Worked check
Check any answer against the anchor: the sample page is 91 bytes and minifies to 64 bytes, with 27 saved. If your copy of the tool gives a different answer for that sample, something has changed in the input, such as an extra space at the start. One check, five seconds, and you know whether the page on screen is the one you meant to minify.
Frequently asked questions
What is the most common HTML Minifier mistake?
Minifying a page with a pre block or a textarea in it. The tool collapses whitespace everywhere, so a 61-byte pre block comes out as one line of 49 bytes.
Can a comment join two words together?
Yes. <p>Hello<!-- note -->world</p> minifies to <p>Helloworld</p>, because the comment was the only thing between the words.
What happens to a script string containing <!--?
It is removed. var s = "<!-- hi -->"; becomes var s = "";, so avoid those characters inside script strings.
Why did my page only save 16%?
Because it was already tight. A 37-byte snippet has only 6 bytes of removable space in it, and the tool removed all 6.
More guides on the HTML Minifier
- How to use the HTML Minifier — step by step
- HTML Minifier explained with worked examples
- HTML Minifier formula — how it actually works
- HTML Minifier for beginners — start here
- HTML Minifier vs doing it by hand — which is faster?
- HTML Minifier — The Complete Guide
- How to get an accurate result from the HTML Minifier
- HTML Minifier for students — with examples
- HTML Minifier for homeowners and DIYers
Try the HTML Minifier — free, in your browser.