HTML, CSS & JS Minifier

Paste code to strip spaces, line breaks and comments and make the file smaller. The language is detected automatically and the savings are shown.

Features

  • Strips spaces, line breaks and comments from HTML, CSS and JavaScript. The language is detected automatically, or you can pick it
  • Shows the size before and after, the percentage saved and an estimate of the gzipped size
  • Safety first: HTML whitespace collapsing is never applied inside pre, textarea, script or style, one space is kept between elements by default, and strings and the spaces in calc() are kept
  • Uses widely used libraries: terser for JavaScript, csso for CSS and html-minifier-terser for HTML
  • Syntax errors are shown by line and column and your original code is never removed. A broken script or style inside HTML is simply left as it is
  • Copy, download, or open a file by drag and drop. Your code is never uploaded

Use cases

Make pages load a little faster

Shrink the HTML and CSS of a small site or landing page that has no build step before you publish it.

Paste compact code into a blog or CMS

Turn CSS or JavaScript for a template or widget into a single line.

See whether minifying is worth it

Compare the size before, after and after gzip side by side.

Check code for syntax errors

JavaScript and CSS are parsed before minifying, so you get the line and column of any error.

Privacy

The code you paste and the files you open are minified inside this browser on this device and are never sent anywhere. The minifier libraries (terser, csso, html-minifier-terser) are loaded from this site the first time you use them. Only your options (comments, spaces, variable names and so on) are saved, in this browser on this device.

FAQ

Will minifying change how my page looks or works?

Only spaces, line breaks and comments that do not affect rendering or behavior are removed. JavaScript only gets shorter variable names and rewrites that keep the same behavior. HTML whitespace collapsing is never applied inside pre, textarea, script or style (script and style are minified as JavaScript and CSS when “Also minify inner <style> and <script>” is on), and one space is kept between elements by default. However, spaces inside elements styled with white-space: pre or similar are collapsed. Wrap such parts in <!-- htmlmin:ignore --> … <!-- htmlmin:ignore --> to leave them untouched. Always check the minified version before you publish it.

It says there is a syntax error

The line and column of the error are shown and your original code is left as it is. Look around that place for an unclosed bracket or quote, or a missing comma. If a <script> or <style> inside HTML has an error, only that part is left unminified and the rest is minified. CSS nesting (the & syntax) and range media queries such as @media (width >= 600px) are not supported; because minifying them would drop rules, they are reported as an error instead.

What is “Gzipped (approx.)”?

Most servers compress files with gzip or similar before sending them. This value is close to what is actually transferred: the browser really gzips the code with CompressionStream and counts the bytes. If your server uses Brotli, the transfer is usually even smaller.

How does the minifier work?

It uses widely used open-source libraries: terser for JavaScript, csso for CSS and html-minifier-terser for HTML. They are hosted on this site and run in your browser, so your code never leaves your device. CSS rules are never reordered or merged, to avoid changing which rule wins.

Can I turn minified code back into the original?

Removed comments and line breaks and shortened variable names cannot be restored. Always keep your original file and edit that one. To put JSON on one line, the JSON Formatter is a better fit.

How large can the code be?

You can open files up to 10 MB. Larger code takes longer; a few megabytes of JavaScript can take several seconds or more.

Related tools

Language

Enter code and it will be minified right away.

You can also drop a file onto this box. Your code is processed on this device and never uploaded.

Result

Before
—
After
—
Saved
—
Gzipped (approx.)
—

Options

Conditional comments such as <!--[if IE]> and comments starting with <!--! are kept.

Includes style attributes and attributes such as onclick. Any part with a syntax error is left as it is.

By default one space is kept around block elements too. Removing it can change the gaps between divs and other blocks laid out with inline-block. Spaces between inline elements such as a, span and button are always kept, because removing them changes the text.

Only names inside functions are shortened. Global names used from outside stay the same.

Your options are saved on this device. The code you paste is not saved.