CSS Minifier & Beautifier
Compress CSS by removing comments and whitespace and merging rules, or reformat minified CSS into readable, indented code. See how many bytes you save.
Your data stays in your browser. This tool processes your input locally and does not upload it to a server.
Input
Output
What does a CSS minifier do, and when should you beautify instead?
A CSS minifier removes comments, whitespace and redundant syntax so a stylesheet downloads faster, while a beautifier does the opposite and re-indents compressed CSS for reading. This tool minifies with csso, which also merges duplicate rules and shortens values, and beautifies with js-beautify, entirely in your browser.
What minifying changes
Minify runs the stylesheet through csso with restructuring turned on and comments removed. Besides stripping whitespace, csso shortens values that mean the same thing: #FFFFFF becomes #fff, #ff0000 becomes red, and margin: 0 0 1.5rem 0 becomes margin: 0 0 1.5rem. It can also merge rules that share a selector and drop declarations that a later declaration overrides.
After each run a note shows the input and output size in bytes and the percentage saved. If the output is larger than the input, the tool says so, which usually means the file was already minified. Minifying does not inline @import files, rewrite url() paths or embed images, so it will not replace a build step that bundles assets.
Beautify for reading and diffs
Beautify re-indents with two spaces, four spaces or tabs, puts each declaration on its own line and leaves a blank line between rules. Use it to read a vendor stylesheet or a minified file from a production site, or to make a one-line CSS snippet reviewable before committing it.
Beautifying only changes layout. It does not validate the stylesheet, reorder rules or fix mistakes, so a missing brace stays missing. Paste the CSS or upload a .css file up to 5 MB, then copy the result or download it as styles.css.
Examples
Minify and merge rules
Input
.card{display:flex;padding:16px 24px;margin:0 0 1.5rem 0;background-color:#FFFFFF}
/* note */
.card:hover{color:#ff0000}
.card{border:1px solid #e5e7eb}Output
.card{display:flex;padding:16px 24px;margin:0 0 1.5rem;background-color:#fff;border:1px solid #e5e7eb}.card:hover{color:red}The comment is removed, the two .card rules are merged, and the colors and margin are shortened. The tool reports 152 to 124 bytes, 18.4% smaller.
Beautify two rules
Input
a{color:red;margin:0}b{padding:0}Output
a {
color: red;
margin: 0
}
b {
padding: 0
}
js-beautify keeps the original declarations. A final declaration without a semicolon stays that way.
Common mistakes and edge cases
- Treating csso as a validator. It is tolerant of broken CSS and may output something odd instead of an error, so check the page after minifying.
- Minifying a file whose rules depend on a particular order, such as rules relying on source order to win a tie. csso aims to preserve behavior, but always test the minified file before deploying.
- Expecting relative url() paths or @import files to be updated. Minifying a stylesheet in a different folder than it will be served from keeps the original paths.
- Editing the minified file by hand. Keep the readable source and re-minify it whenever you change it.
- Assuming a smaller file always helps. If your server already compresses text with gzip or Brotli, the gain from minifying is smaller than the byte count suggests.
How to use this tool
- Paste CSS or upload a .css file.
- Choose an indentation, then Beautify or Minify.
- Copy the result or download styles.css. The note shows the bytes saved.
Frequently asked questions
Is my CSS uploaded to a server?
No. csso and js-beautify are JavaScript libraries that run in your browser tab, and the CSS you paste or upload is never sent anywhere. That makes the tool suitable for unreleased stylesheets and private client work. The page does not store your input, so closing the tab clears it. You can confirm this yourself by opening your browser’s network panel while you minify, where no request carrying your code appears.
Will minified CSS look exactly the same in the browser?
It should. csso shortens colors and lengths to equivalent forms, removes whitespace and comments, and merges or removes rules only when the cascade result is the same. Unusual hacks, vendor prefixes in odd orders and rules that rely on invalid CSS parsing are the cases where a difference is most likely, so compare the page before and after for anything important.
What is the difference between minify and compress?
Minifying rewrites the CSS text so it contains fewer characters. Compression, such as gzip or Brotli, is applied by the web server when it sends the file and is undone by the browser. They stack: a minified file compresses to a smaller size than an unminified one, so do both in production.
Does the tool keep comments?
Minify removes all comments, including license banners and any comment that explains a hack. If a license requires keeping a header comment, copy it back above the minified output before publishing, and keep the commented original as your working source. Beautify never removes comments, because it only changes whitespace and indentation, so it is the safer choice when you are only reading or reviewing a file.
Is there a file size limit?
Uploads are limited to 5 MB, which is far larger than most stylesheets. Pasted input is not capped by the tool, but everything is processed on your own device, so very large input depends on your computer’s speed and memory. The browser may pause briefly while csso restructures the rules, and splitting a huge file into parts is an easy workaround.
References
Last reviewed
Related tools
JavaScript Minifier & Beautifier
Minify JavaScript with Terser or beautify it for reading.
Formatters & BeautifiersJSON Formatter & Validator
Format, minify, and validate JSON with clear error locations.
Formatters & BeautifiersXML Formatter & Validator
Format, minify, and check XML syntax.
Formatters & Beautifiers