CSS Minifier vs doing it by hand — which is faster?
For a short rule, removing the spaces by hand feels fast enough. For a whole stylesheet, or anything that has to stay correct, the CSS Minifier is faster and far less likely to slip. The honest answer is to use your head for a quick guess and the tool for the real thing, and the comparison below shows why.
At a glance
By hand: the easy cases
If you only need to tidy one short rule, doing it by hand takes seconds. Take this button rule, 45 bytes written over five lines:
.btn {
color: blue;
background: white;
}Removing the line breaks, the indent spaces, the spaces after the colons and the final semicolon gives .btn{color:blue;background:white}, which is 33 bytes, saving 12 bytes. That is four small edits, and most people can do them without a mistake. For a single rule that nobody else will read, hand-editing is fine.
By hand: the slow cases
Now try a longer block by hand. This page stylesheet has four rules, a comment, and 186 bytes:
.page {
font-family: Georgia, serif;
line-height: 1.6;
color: #333;
}
.page h1 {
font-size: 28px;
margin-bottom: 12px;
}
/* header styles */
.page p {
margin-bottom: 16px;
}Minified, it becomes .page{font-family:Georgia,serif;line-height:1.6;color:#333}.page h1{font-size:28px;margin-bottom:12px}.page p{margin-bottom:16px}, which is 129 bytes, saving 57 bytes, or 31% smaller. Doing that by hand means deleting the comment, collapsing eleven lines into one, removing the spaces around every brace, colon and semicolon, and dropping three semicolons, all without deleting a space that matters, such as the space between .page and h1 or the space after the comma in Georgia, serif. That is several minutes of careful editing, plus the time to count the bytes afterwards. With the tool you paste the block and read 129 bytes at once.
A second comparison: checking your own work
The harder part of doing it by hand is not the typing, it is the checking. Every space you remove is a decision: is this space needed, or not? The space after the comma in Georgia, serif is needed, because it separates two font names. The space between .page and h1 is needed, because it is part of the selector. The space after the colon in color: #333 is not needed. One wrong call and the CSS still looks minified but behaves differently, and the fault will not show up until someone loads the page and a heading sits in the wrong place. The tool makes those calls by rule, the same way every time, and it shows the byte count as proof.
When the tool wins outright
Use the tool when the stylesheet is longer than a few rules, when it has comments to remove, or when the byte count matters, such as a file that loads on every page of a site. Use your hand only when the CSS is a throwaway fragment and nobody will read it closely. The dividing line is simple: if anyone else will load the page, generate the minified CSS; if only you will see it, editing a couple of lines yourself is fine.
The common mistake
People minify by hand and delete the space in a descendant selector, turning .page h1 into .pageh1, which matches nothing on the page. The tool never makes that mistake, because it only removes spaces around punctuation, and the space between two selector words is not around punctuation. If a heading loses its styling after a hand minify, check the selectors first: a missing space is the most likely cause.
Frequently asked questions
Is it faster to minify CSS with a tool or by hand?
With the tool for anything longer than a few rules. A 186-byte stylesheet takes seconds with the tool, against minutes of careful editing by hand.
How much does a 186-byte stylesheet shrink?
From 186 bytes to 129 bytes, saving 57 bytes, which is 31% smaller.
What is the hardest part of minifying by hand?
Deciding which spaces matter. The space in .page h1 and after the comma in Georgia, serif must stay, while the space after a colon can go.
When is minifying by hand fine?
When the CSS is a short throwaway fragment only you will see. If anyone else will load the page, use the tool.
More guides on the CSS Minifier
- How to use the CSS Minifier — step by step
- CSS Minifier explained with worked examples
- CSS Minifier formula — how it actually works
- CSS Minifier for beginners — start here
- Common mistakes people make with the CSS Minifier
- CSS Minifier — the complete guide
- How to get an accurate result from the CSS Minifier
- CSS Minifier for students — with examples
- CSS Minifier for homeowners and DIYers
Try the CSS Minifier — free, in your browser.