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

Steps

  1. 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 .button rule further down.

  2. Look at what changed

    The colours are shortened, the padding shorthand is collapsed and the two .button rules 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}
  3. 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.

  4. 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.

Try it now

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:

Tutorial · 5 min · beginner

How to minify an HTML landing page

Shrink a landing page with inline CSS and JavaScript, remove comments and default attributes, and check the saving before publishing.