Minify CSS with csso: shorter colors, duplicate rules merged, license comments kept (or all, or none), size saved in bytes
Shrink a stylesheet for production: spaces and comments go, values get their shortest form, and rules that say the same thing are merged.
How to use it
Paste CSS, or open a .css file. Pick which comments stay: license comments (/*!), all, or none. Read the size in bytes in the status bar, before and after, with the percent saved; copy it or download minified.css.
Examples
Shorter colors and zeros
.alert {
color: #ff0000;
margin: 0px 0px 4px 0px;
}.alert{color:red;margin:0 0 4px}Rules with the same declarations merged
.error {
color: red;
}
.warning {
color: red;
}.error,.warning{color:red}License comments kept
/*! Theme v2 | MIT */
/* layout */
.page {
max-width: 960px;
}/*! Theme v2 | MIT */
.page{max-width:960px}A comment starting /*! is kept, as licenses ask; others go.
Every comment kept (Comments: All)
/* layout */
.page {
max-width: 960px;
}
/* type */
h1 {
font-size: 2rem;
}/* layout */
.page{max-width:960px}
/* type */
h1{font-size:2rem}Each comment between rules stays on its own line.
How it minifies
Questions
- Is merging rules safe?
csso merges rules only where moving them doesn’t change which declaration wins, so each element keeps the same styles. - How much smaller will it get?
It depends on how the stylesheet was written: one full of comments and spaces shrinks a lot, one already minified hardly at all. The status bar shows the bytes and the exact percent for yours. - Is my CSS uploaded?
No. Everything runs in your browser, so your stylesheet stays on your device. Nothing you paste is uploaded unless you share a result, which is locked with your password first.