CSS & JS Minifier

Minify CSS & JavaScript by removing comments and whitespace. Reduces file size and includes a CSS beautifier for formatting.

๐Ÿ“ Drag and drop .css / .js files or click to select
Files are read in the browser only ยท Max 8MB
Result

โš  This is a safe minification, removing only whitespace and comments. It does not perform advanced minification like variable name mangling or dead code elimination, as renaming with a custom parser can silently break code. For maximum reduction, use terserยทesbuildยทcssnano in your build step.
๐Ÿ›ก Contents within strings, template literals, and regex literals are left untouched. For JS, line breaks are only removed where they cannot act as semicolons (ASI). / If it's ambiguous whether / is division or regex, minification is aborted, and the original code is kept. The result is re-checked by the browser's parser after minification.
๐Ÿ” However, syntax checking does not guarantee behavioral equivalence. Code that reads function sources as strings (Function.prototype.toString) or code that assigns meaning to comments (@license, webpackChunkName) may be affected, so verify actual behavior before deployment.

What is the CSS & JS Minifier?

Comments and whitespace make code readable but increase file sizes. This online tool minifies CSS and JavaScript by safely stripping only comments and unnecessary spaces, showing you the exact size reduction. It's a conservative approach: we don't shorten variable names or alter code inside strings and regular expressions, preventing silent errors. For JavaScript, it carefully preserves line breaks that might affect execution. Everything, from minification to syntax validation, happens in your browserโ€”your code is never sent to our servers. It's a free, fast way to shrink single files or inline scripts.

How to use

  1. Paste your CSS or JS code into the "Source code" box, or drag and drop a .css or .js file. The language is typically auto-detected.
  2. Click "Minify" to remove comments and whitespace. The minified code and file size savings will appear in the "Result" panel.
  3. For minified CSS, click "Beautify (CSS)" to format the code back into a readable layout with proper indentation.
  4. Review any warnings and adjust options like preserving license comments (`/*!*/`) if needed.
  5. Click "Copy" to copy the result to your clipboard, or "Save" to download it as a .min.css or .min.js file.

CSS & JS Minifier guide

How this tool is used in real work, and what to watch out for.

The effect of minification is reduced if you're already using gzip

Let's be honest: minification mostly removes whitespace and newlines, which are the exact patterns that compression algorithms like gzip and Brotli are best at. For a compressor that already excels at reducing repetitive patterns to just a few bytes, removing that repetition beforehand doesn't make a huge difference.

The general trend is this: even if minification achieves a 30% raw size reduction compared to the original, the savings after gzip are usually much smaller. So don't mistake a claim like "minification saved 30%" for an equivalent reduction in actual transfer size.

This is why this tool's stats include a "Result after gzip" figure. That number is much closer to what actually travels over the network. Try it yourself: measure the gzipped size of your original source, then compare it to the gzipped size of the minified result. If the difference is only a few KB, then minification is more about source obfuscation than transfer size savings.

To put it in order: 1) First, make sure your server has gzip or Brotli enabled (this has the biggest impact). 2) Then, minify. 3) And then, set cache headers. Using only minification on a server without compression is doing things backward.

When this tool is enough ยท When you should use a build tool

This tool only performs safe minification, like removing whitespace and comments. It does not perform advanced optimizations like variable name mangling, dead code elimination, or property merging. The savings are lower than dedicated tools not because it lacks features, but because we chose not to implement themโ€”renaming identifiers with a custom parser can silently break code that relies on dynamic references.

ScenarioRecommendation
Sites without a build step (e.g., WordPress themes, static HTML sites)This tool is sufficient
Quickly minifying a single script or inline styleThis tool
Custom CSS pasted directly into a CMS admin panelThis tool
When you need to read minified CSSThis tool's "Beautify (CSS)"
Projects that already use npm and a bundleresbuild ยท terser ยท cssnano โ€” for much greater savings and automation
Minifying dozens of files for every deploymentA build pipeline โ€” this is not a manual copy-paste job
When you need maximum savings (e.g., mobile initial load)Bundler + tree-shaking + code splitting

What to watch out for in CSS minification

When the 'CSS colors ยท 0 shorthand' option is enabled, six-digit hex colors are shortened to three digits, and values like `0.5em` become `.5em`. There are a few pitfalls here.

  • You have to distinguish whether `#abcdef` is a color value or an ID selector. This tool only shortens colors when they appear in a property value, so it won't touch the same string if it's used as a selector.
  • Whitespace inside `calc()` is significant. Removing the spaces around the minus sign in `calc(100% - 20px)` breaks the calculation entirely. This tool does not touch the contents of `calc()`.
  • Comments starting with an exclamation mark (`/*!`) and `@license` comments are kept if the '`/*!*/ ยท @license comments`' option is checked. Be sure to keep this enabled when minifying open-source libraries. Removing license notices is a license violation.
  • If the minified result is unreadable, you can use the "Beautify (CSS)" button to reformat it. However, comments that were removed will not come back. Always keep a copy of your original source.

JS Minification โ€” Why aren't all newlines removed?

JavaScript has Automatic Semicolon Insertion (ASI), which means newlines can sometimes act as semicolons. Recklessly joining all lines can change how the code behaves.

  • This tool only removes newlines in places where a statement must continue, such as after commas, operators, or opening parentheses. Other newlines are preserved. This is why the result is not always a single line.
  • In the rare case that it's ambiguous whether a slash (`/`) is for division or a regular expression, minification is aborted to be safe, and you'll be told why. If your code didn't get smaller, this might be the reason.
  • After minification, the result is re-checked by the browser's parser. If the syntax is broken, the result is discarded.
javascript
// The newline after return is interpreted as a semicolon, causing it to return undefined
function f() {
  return
  { ok: true }
}

// Conversely, removing this newline changes the behavior
var a = b
(function(){})()   // If joined, it becomes a call: b(functionโ€ฆ)
Passing a syntax check does not guarantee behavioral equivalence. Code that reads function source as a string (`Function.prototype.toString`), code that assigns meaning to comments (`@license`, `webpackChunkName`), or error reporting that depends on line numbers from stack traces may be affected. Always verify the actual behavior before deploying.

What to do if minification breaks your code

  1. First, check if the original source code was already broken. This tool validates the result with the browser's parser, so if an error occurs, it's highly likely the original source already had a syntax issue.
  2. Check if the language auto-detection was wrong. Files with mixed content like CSS-in-JS or HTML snippets can confuse the detector. Try manually selecting the CSS or JS tab and running it again.
  3. If you pasted multiple concatenated files, try minifying them one by one. This will quickly narrow down which file is causing the problem.
  4. See if directives like `@license` or `webpackChunkName` were removed. Enable the option to preserve `/*!*/` comments.
  5. If it still doesn't work, don't use this tool to minify it. It's time to set up a proper build tool. Working code that's less compressed is better than compressed code that's broken.
The contents of strings, template literals, and regex literals are not touched, not even a single character. If text inside a string or spaces within a regex pattern have disappeared, this tool is not the cause.

Frequently asked questions

Will this reduce file size as much as terser or cssnano?

No. This tool safely removes only comments and whitespace. It doesn't rename variables, so build tools like `terser` or `cssnano` will produce smaller files.

Why aren't JavaScript variable names shortened?

To prevent bugs. Safely renaming variables requires a complex parser. This tool avoids that risk, as simple replacement can alter words in strings or break global code.

Is my code sent to your server?

No. All processing happens 100% in your browser. Your code is never sent to our servers, so it's safe to use with private or internal source code.

What is removed from CSS during minification?

It removes comments (except `/*!` licenses), whitespace, and the last semicolon in a block. It also shortens hex colors (#ffffff โ†’ #fff) and values (0.5 โ†’ .5).