CSS and JavaScript Minifier
Paste CSS or JavaScript to remove comments and unnecessary whitespace and see how many bytes you save. The minifier is deliberately cautious: it never touches strings, template literals or regular expressions, and keeps JavaScript line breaks where removing them could change behaviour. It suits snippets, inline code and quick checks; use a build tool for production bundles.
CSS and JavaScript Minifier
This is a basic minifier. It removes comments and extra whitespace but does not rename variables or rewrite code. The JavaScript option keeps line breaks where removing them could change behaviour, and stops if it cannot read the code safely. For production builds, use a build tool such as esbuild, Terser or Lightning CSS. Comments starting with /*! (usually licences) are kept.
Runs in your browser. Nothing you enter is uploaded or saved.
How to use this tool
- Choose the language. Select CSS or JavaScript.
- Paste your code. Paste the code you want to shrink into the input box.
- Minify. Press Minify and check the before, after and saved figures.
- Test and copy. Copy the output and test it on the page before replacing the original.
What this minifier does
For CSS it removes comments, collapses whitespace and drops the last semicolon in each block. For JavaScript it removes comments and extra spaces but does not rename variables, remove dead code or rewrite syntax, so savings are smaller than with a full minifier.
Use a build tool for production
Tools such as esbuild, Terser and Lightning CSS parse the code properly, shorten names and produce source maps. Add one to your build so minification happens automatically every time.
Minification and page speed
Smaller files download and parse faster, which can help loading metrics. Combine minification with Brotli or gzip compression on the server, and remove unused CSS and JavaScript for bigger gains.
Frequently asked questions
Can minifying break my code?
It can, with any tool, if the code relies on unusual syntax. This minifier stops with an error when it cannot read the code safely. Always test the result.
Are licence comments kept?
Yes. Comments starting with /*! are kept, which is the usual convention for licence notices.
Should I minify HTML too?
It helps a little, but server compression gives most of the benefit. Focus on CSS and JavaScript first.