HTML Minifier — CSS & JS too

Free HTML minifier that also minifies CSS and JavaScript in your browser. No signup, and your code is not uploaded. Try UtilGenie.

By

Developer tools

Runs in your browser. No signup required.

Three modes that do different work

HTML mode is a whitespace collapse: newlines are removed, runs of whitespace become a single space, and spaces between > and < are removed. Comments stay. Text inside <script> and <pre> is collapsed too, which can break a script that relied on a newline, or a poem inside pre. It is not an HTML parser and it does not drop optional tags.

CSS mode calls csso, the same library as the dedicated CSS minifier. JavaScript mode calls terser with compress and mangle, the same settings as the dedicated JavaScript minifier. Switching the mode does not convert one language into another. Paste the kind of source the selected tab names.

A small document you are about to paste into a host

The HTML sample is a div with a span and extra space. HTML mode pulls it onto a tighter line and keeps the words. Use that for a snippet you are embedding, then view the result. If the page is a real site, use a build step that understands templates. This box will not rewrite asset URLs or hash filenames.

JavaScript mode is the one to use when the script itself should be mangled. HTML mode will not look inside a script to rename variables. CSS mode will not read a <style> block out of an HTML paste. Split the file if you have all three.

Errors and the original

CSS and JavaScript modes surface a failure instead of a half-minified file. HTML mode rarely “fails”; it just applies the three replaces, so bad HTML comes back still bad, only flatter. Keep the source you can edit. The output is for the copy you ship.

Nothing is uploaded. A minified script is harder to debug and this page does not emit a source map. The separate JavaScript and CSS pages are the same engines with a single language on screen, which is calmer when you are only holding one file.

HTML mode deletes newlines instead of turning them into spaces

HTML mode runs three replaces and nothing else. Every newline is removed. A run of two or more spaces becomes one space. A space between > and < is removed. Comments, attributes, and words stay. The sample div with a span and a leading indent becomes <div class="box"><span> Hello </span></div>. The space inside the span survives because it is a single space between letters, not a gap between tags.

A preformatted block is not protected. A pre element whose text is line 1, then a blank line, then line 2, comes back as <pre>line 1line 2</pre>. The line break a person would read as a space is deleted, so the two lines are glued together. The same delete happens inside a script. Source that is function f(){ then a newline, return, a newline, and 1 comes back as function f(){return1}, which is a different program. Use JavaScript mode when the script itself should be minified.

CSS and JavaScript modes are the other engines

CSS mode calls csso on the whole box. JavaScript mode calls terser with compress and mangle, the same pair of settings as the dedicated JavaScript page. Neither mode hunts through an HTML document for a style or script block. Paste the language the selected tab names. Switching tabs clears the output and the error.

CSS and JavaScript failures leave the output empty and show the exception text, or the fallback “Minify failed. Check your syntax.” HTML mode almost never throws. Bad markup comes back flatter and still bad. Keep the editable source. This page does not emit a source map, and it does not upload either box.

Choose the mode before you trust the shorter file

A snippet you are about to paste into a CMS HTML field can use HTML mode if you have looked at the result and the text nodes still read correctly. A stylesheet belongs in CSS mode, or on the dedicated CSS page, which uses the same library. A script that other pages call by its function name can break under mangle. There is no switch to turn mangle off.

Do not expect asset URLs, template tags, or a framework build to be understood. The HTML replaces do not know that a newline inside a string was significant. If the shorter file behaves differently in the browser, go back to the source you can still read. An HTML comment survives, because none of the three replaces looks for comment markers. A newline inside a template’s text node is deleted the same way as a newline in ordinary HTML.

How to use HTML/CSS/JS Minifier

  1. 1

    Choose HTML, CSS or JS with the buttons at the top.

  2. 2

    Paste your code into the Raw box.

  3. 3

    Press Minify.

  4. 4

    Read the result in Minified Output and press Copy.

FAQ

Which languages can I minify here?

This HTML minifier switches between HTML, CSS, and JavaScript. CSS uses a CSS minifier, JavaScript uses Terser, and HTML collapses extra whitespace.

Does HTML minifying remove code inside scripts?

The HTML mode only collapses whitespace in the document you pasted. Use JavaScript mode if you want a script compressed and mangled.

Is the code uploaded?

No. Each minify runs in the browser.

Should I minify source I still need to edit?

Keep the original. Minified output is for shipping a smaller copy, and mangled JavaScript is harder to debug.

Will HTML mode minify the script inside the page?

It only collapses whitespace, including whitespace inside script and pre. It does not mangle JavaScript. Switch to JavaScript mode for that, with the script alone in the box.

Are HTML comments removed?

No. The HTML replaces do not strip comments. They remove extra whitespace and spaces between tags.

What does HTML mode do to the sample div?

The indented div and span become <div class="box"><span> Hello </span></div>. Newlines and the indent are removed. The single space inside the span stays.

Why did two lines inside pre become one word?

Newlines are deleted, not replaced with a space. <pre> followed by line 1, a blank line, and line 2 comes back as <pre>line 1line 2</pre>. The same delete can glue a return statement to the next token.