A CSS minifier makes your stylesheets smaller by removing everything that a browser doesn't need. Paste your code, press Minify, and this CSS minifier strips out comments, line breaks and extra spaces, then shows you how many bytes you've saved. Switch to JavaScript, and it does the same job for scripts, with a cautious approach that keeps the code working exactly as it did. Smaller files mean less data to download. All of the work happens in your browser, so your source code stays on your own device.
How to use the CSS minifier
- Choose CSS or JavaScript.
- Paste your code into the box.
- Press Minify.
- Check how much you saved, and copy the result.
- Test the minified file before you publish it.
What is minification?
Minification is the process of removing all unnecessary characters from source code without changing its functionality. These characters usually include whitespace, new lines and comments. It differs from data compression, as minified code can be run immediately, with no decompression step, by the same interpreter that handles the original. Unlike obfuscation, its goal is simply to make files smaller, not to hide how the code works.
A CSS example
Take this rule: a { color: red; margin: 0 auto; }. After minifying, it becomes a{color:red;margin:0 auto}. The spaces around the braces, after the colons and the final semicolon have all gone, but the rule means exactly the same thing. The space inside the margin value is kept, because it separates two separate values. Strings and url() values are copied across unchanged.
What gets removed
| Removed | Kept |
|---|---|
| Comments | Text inside strings |
| Line breaks and indentation | Spaces that separate values |
| Spaces around braces and commas | The spaces in CSS calculations such as calc() |
| The last semicolon in a CSS rule | Variable and function names |
How the JavaScript minifier stays safe
JavaScript is trickier than CSS. The language can insert semicolons automatically at line breaks, so removing the wrong line break can change what a program does. This tool takes a cautious approach. It removes comments and spare spaces, and it joins lines only where that's clearly safe, such as after an opening bracket or a semicolon. It keeps any line break that might matter. It also recognizes strings, template literals and regular expressions, so their contents are never altered. It doesn't rename variables or rewrite your logic.
That approach means that the result won't be as small as the output from a full build tool, which also shortens names and removes unused code. For a production website with a build process, use the minifier in your build. This page is ideal for a quick job on a single file, such as a small script for a landing page or a theme customization.
Why minify at all?
- Faster downloads. Fewer bytes reach the visitor sooner.
- Lower data use, which matters to people on mobile plans.
- Reduced bandwidth costs on busy websites.
- Quicker page rendering, as CSS has to be downloaded and processed before a page can be displayed.
Minification and compression
Most web servers also compress files before sending them, typically using gzip or Brotli. The two techniques work well together. Minifying first removes content that doesn't need to exist at all, and compression then shrinks whatever remains. The savings shown on this page are for the raw file, so your real transfer size after compression will be smaller still.
Good habits
- Keep your original files. Edit those, and generate the minified version again.
- Name minified files clearly, for example style.min.css.
- Test before you publish, particularly with hand-written scripts.
- Check licenses. Removing comments also removes any license notices, and some licenses require you to keep them.
Is my code private?
Yes. Your code is processed on your own device and it isn't uploaded. That makes the tool suitable for private projects.
When not to use a minifier
During development, keep your code readable, because line numbers and comments make debugging much easier. Minify as the final step before you publish, and keep source files under version control. If your site already has a build tool, let it handle minification automatically, since doing the job twice adds nothing. If something breaks after minifying, compare the two versions by pasting them into a diff checker, or restore the original and look for code that relies on unusual formatting.
How much will you save?
Savings depend on your coding style. A heavily commented file with deep indentation can shrink dramatically, while code that's already compact will change very little. The percentage at the top of the result shows the exact saving for your file, so you can decide whether the extra step is worthwhile.
Common mistakes
- Editing the minified file. Always change the original.
- Removing license comments that you're required to keep.
- Skipping the test. Check that everything still works.
Related developer tools
Make markup readable with the HTML formatter, check layouts with the screen resolution checker, and compare versions with the diff checker.
What next
Use this often? Add CSS and Java to your Home screen.
Frequently asked questions
How does the CSS minifier work?
It removes comments and whitespace that browsers don't need, while keeping strings and values intact.
Can it minify JavaScript?
Yes. Switch to JavaScript. It keeps any line break that might affect how the code runs.
Does minifying change how code works?
It shouldn't, but always test the result before publishing.
Should I keep my original file?
Yes. Edit the original and minify it again whenever you make changes.
Is my code uploaded?
No. It's processed in your browser.
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.