Code Minifier · Tutorial
How to shrink a stylesheet before uploading it
4 min readbeginnerUpdated
Hand-written stylesheets carry comments, spacing and repeated rules that browsers don't need. You will minify one, see which parts were shortened and save it as a .min.css file.
What you need
- The Code Minifier
- A CSS file, or the example site styles
Steps
Open the stylesheet
Drop your .css file on the page or load the example: header and button styles with comments, a licence line and a second
.buttonrule further down.Look at what changed
The colours are shortened, the padding shorthand is collapsed and the two
.buttonrules are merged into one. The licence comment stays at the top./*! Site styles | (c) Example Studio */ .header{display:flex;justify-content:space-between;padding:16px 24px;background-color:#fff}Decide about merging
If your stylesheet relies on the exact order of rules, for example to override a framework, turn Merge rules off and compare the result.
Save it
Press Download to save styles.min.css and update your link tag to point at it.
Try it yourself
Opens the Code Minifier with this tutorial's sample loaded.
Common mistakes
- Editing the minified file later
- Change the readable stylesheet and minify it again. Edits made to the .min.css file are easily lost.
- Pasting SCSS
- Variables and nesting are Sass features. Compile them with the SCSS to CSS compiler first.
Next steps
Go back to the Code Minifier, or keep going with one of these: