Developer HTML / CSS / JS Minifier

HTML / CSS / JS Minifier

Minify HTML, CSS, or JS by stripping comments and unnecessary whitespace, entirely in your browser.

69 B → 50 B (28% smaller)

How to use this tool

Choose HTML, CSS or JS and paste the code. The minified version and the size before and after appear as you type. Copy it into the file you're publishing, and keep the readable original as the one you edit.

Measured on this site's own files

  • The HTML page shell: 6,398 bytes down to 3,624, 43% smaller, mostly indentation and comments.
  • The main stylesheet: 2,262 bytes down to 1,421, 37% smaller.
  • A 7,889-byte JavaScript module with long comments: 6,605 bytes, 16% smaller. The minified copy was run and gave exactly the same results as the original.

JavaScript shrinks least here because line breaks are kept (removing them safely needs a full parser) and names aren't shortened. If your server compresses files with gzip, the real saving is smaller in bytes, because gzip already squeezes repeated whitespace: gzipped, the module went from 3,015 to 2,504 bytes, 511 bytes saved rather than 1,284.

What it leaves alone, on purpose

  • Strings, template literals and regular expressions in JS are copied exactly, so a multi-line template keeps its indentation and a // inside /https?:\/\// isn't taken for a comment.
  • In CSS, the space before a colon stays: .nav :hover (any hovered element inside .nav) means something different from .nav:hover. Text inside quotes, such as content: "Note: a, b", isn't touched.
  • In HTML, a single space stays between tags, since <b>Hello</b> <i>world</i> would otherwise read "Helloworld". <pre> and <textarea> keep their spacing, attribute values keep theirs, and inline <script> and <style> are minified with the JS and CSS rules.

Frequently Asked Questions

Is this a replacement for Terser, cssnano, or html-minifier in my build pipeline?

No. Those tools parse the code fully, so they can also shorten variable names, drop unused code and merge CSS rules, and they run automatically every time you build. This is for a quick one-off: a snippet for a CMS, an email template or a page without a build step.

Will minifying ever break my code?

It is written to avoid the usual causes: it never edits strings, regular expressions or preformatted text, and it keeps JavaScript line breaks so statements without semicolons still end where they did. Unusual constructs can still confuse a minifier that doesn't fully parse the code, such as a regular expression right after a closing bracket, so test the result before replacing a live file.

Why is the JavaScript output still on many lines?

JavaScript allows a statement to end at a line break instead of a semicolon. Joining lines without understanding every statement could merge two of them into one different statement, so each line break is kept as a single newline, and only the indentation, blank lines and comments around it are removed.

Related Tools

Related Blog Posts