Developer Tools

Speed Up Your Website How to Minify CSS the Safe Way

Stylesheets block a page from showing until they load, so every kilobyte matters. Minifying CSS is a quick, safe win, if the tool knows which spaces to keep.

Quick answer: minifying CSS removes comments, spaces and line breaks without changing how the page looks, usually cutting the file by 15 to 30%. Paste a copy of your stylesheet into the CSS Minifier, check the page still looks right with the minified file, and keep the original for editing.

In this article
  1. Why CSS size matters
  2. What minifying removes
  3. The spaces that must stay
  4. License comments
  5. How to minify
  6. Check before and after
  7. On WordPress
  8. Bigger CSS wins
  9. Do the same for JavaScript

Why CSS size matters

Browsers must download and read CSS before they can show a styled page, which makes stylesheets “render-blocking”. A smaller stylesheet means the first view of the page appears sooner, one of the things measured by Google’s Core Web Vitals, such as Largest Contentful Paint.

CSS MinifierMinify CSS by removing comments, whitespace and unneeded semicolons. Keeps strings, calc() spacing and license comments safe. Shows bytes saved.
Open the free tool

What minifying removes

  • Comments (/* … */).
  • Line breaks, indentation and spaces around { } : ; ,.
  • The last semicolon before a closing brace.

The result looks the same in the browser but is typically 15 to 30% smaller for hand-written CSS, more if it was heavily commented.

The spaces that must stay

Careless minifiers break styles by removing spaces that matter:

CaseMust stay asWhy
calc(100% - 20px)spaces around + and −Without them, calc() is invalid
.menu aspace between selectorsIt means “a inside .menu”
content: "Read more"text in quotes untouchedIt is displayed on the page
margin: 0 autospace between valuesSeparate values

The CSS Minifier handles all of these, and never touches text inside quotes.

License comments

Open-source CSS often requires its copyright notice to be kept. By convention, comments starting with /*! are preserved by minifiers. Tick the option to keep them when you minify third-party code.

How to minify

  1. Paste your stylesheet into the CSS Minifier.
  2. Choose whether to keep /*! license comments.
  3. Copy or download the minified CSS and check the size saving.
  4. Keep your readable original, edit that, then minify again.

Check before and after

Open the page in your browser, then open developer tools (F12) and look at the Network tab to see the stylesheet’s size before and after. Reload a few key pages, home, a product or article, the contact form, and compare them visually with the old version. Any difference usually points to a selector or calc() expression that needs attention.

On WordPress

Many caching and performance plugins minify CSS automatically. Manual minifying is useful for custom code you add in the Customizer’s “Additional CSS” box, child themes and small static sites. Do not paste minified code into a file you plan to edit later, keep a formatted copy for yourself.

Bigger CSS wins

  • Remove unused CSS: themes and frameworks ship styles for components you never use. Removing them often saves far more than minifying.
  • Enable compression (gzip or Brotli) on your server, it shrinks CSS dramatically.
  • Combine small files to reduce requests, especially on older HTTP/1.1 servers.
  • Cache: set long cache times and change the file name or version when it changes.

Do the same for JavaScript

Scripts benefit too, try the JavaScript Minifier. To read minified HTML from another site, format it with the HTML Formatter. Everything runs in your browser.

Frequently asked questions

How much does minifying CSS help?

It often reduces CSS size by 15 to 30 percent, which helps pages load faster on mobile.

Can minifying break my styles?

Proper minification keeps the same rules. Test the site after replacing files.

Should I edit the minified file?

No. Edit the original file and minify again.

Do caching plugins minify CSS?

Many do. Avoid minifying twice to prevent conflicts.

Is minifying the same as compression?

No. Minifying removes characters, while server compression such as gzip shrinks the file during transfer. Use both.

Does minifying CSS change my design?

No. Only whitespace and comments are removed, so the rules and the look stay exactly the same.

Is minifying CSS still worth it with fast internet?

Yes, especially on phones. Smaller CSS reaches the browser sooner, and CSS has to load before the page can be drawn.

Should I combine my CSS files too?

Fewer, smaller files help, but with modern HTTP/2 hosting the bigger win usually comes from removing unused CSS.

CSS MinifierMinify CSS by removing comments, whitespace and unneeded semicolons. Keeps strings, calc() spacing and license comments safe. Shows bytes saved.
Open the free tool
Keep reading

Related articles

All articles
Dev

How to Minify JavaScript Without Breaking It

Removing comments and whitespace from JavaScript shrinks files and speeds up pages. Doing it carelessly breaks code in surprising ways, here is what to watch.

3 min read
Dev

How to Clean Up Messy HTML Code (and Find Problems Faster)

HTML from page builders, email templates and “view source” is often one long line or a tangle of tags. Formatting it is the first step to understanding and fixing it.

3 min read
Dev

Should You Minify JSON? Size, Speed and How Gzip Changes the Picture

Minifying JSON removes spaces and line breaks. It sounds like an obvious win, but how much does it really save, and when should you not bother?

3 min read