CSScompressor Nederlands

HTML minifier

Compress HTML and the CSS and JavaScript inside it, in one pass. Content of pre and textarea is left exactly as it is.

Compression level

JavaScript is switched off. The button below still works: compression then happens on the server.

Why HTML is the trickiest of the three

In CSS and JavaScript, whitespace outside strings almost never matters. In HTML it sometimes does: a space between two inline elements is a real, visible space. Remove it and <a>link</a> <b>bold</b> renders as "linkbold". So an HTML minifier has to know which gaps it is allowed to close.

This one takes the conservative route. Runs of whitespace collapse to a single space everywhere, and whitespace is removed completely only next to block-level tags — div, p, li, section, table rows and the like — where a browser would not render it anyway. Between inline elements a single space survives, so your text keeps its spacing.

What happens to each part

Where the real win is

Honestly: HTML minification is the smallest of the three wins. A typical page saves 10 to 20 percent, and gzip would have found most of that anyway. It is worth doing as the last step of a build, and it is genuinely useful for email templates and embedded widgets where every byte is inlined and there is no gzip at all. It is not worth hand-running on every page edit — let your build or your template engine do it.

If your goal is a faster page, the bigger levers are elsewhere: fewer requests, images in the right format and size, and getting CSS off the critical path. That last one is covered on CSS optimization for speed.

Will minifying break my layout?

It can, if your layout depends on whitespace between inline-block elements — an old grid trick. Collapsing those spaces to one is safe; removing them is not, which is why this tool only removes whitespace around block-level tags. Check the result before shipping it.

Does it touch my JSON-LD structured data?

No. Script blocks with a non-JavaScript type are left as they are, apart from trimming the whitespace at the very start and end. Your schema markup keeps working.

Can I minify a PHP or template file?

Not safely. PHP tags, Twig braces and Blade directives are not HTML and can be split by whitespace changes. Minify the rendered output instead, at the end of your build or through output buffering.

Should I serve minified HTML or use gzip?

Both, and gzip matters more. Enable compression on your server first — that is one configuration line for every page you will ever serve — and treat HTML minification as the extra few percent on top.

Other tools on this site

Read more