CSS Tools That Compress & Strip Unused Styles From Your CSS Files
People who are not web designers can compress CSS files in three easy ways:
(a) Strip whitespaces like spaces, tabs, etc. (b) Remove all unused CSS classes & IDs (c) Use shorthand mode (use #CCC instead of #CCCCCC, replace 1.0em with 1em, etc)
Now all these are very minor changes but quickly add up and may make your CSS file lighter by a few kilobytes. This translates to faster web pages as smaller files take relatively less time to download.
And fortunately, there are plenty of CSS tools available online that can do all this for you - they will analyze your CSS files, remove unwanted stuff and thus reduce the overall size.
Clean CSS - This tool pulls the CSS code from your website and optimizes it by removing comments, compressing the color codes and converting to shorthand mode CSS. It also outputs a detailed log so you know exactly what has changed in the background.
The tool offers various levels of compression depending upon how readable you want the code to be for humans.
CSS Checker - This is probably the most useful CSS tool as it helps you find orphaned CSS styles (Classes, IDs, etc) that are present in the stylesheet but not used in the web pages.
You type the URL of your CSS file and a list of web pages that use that particular styles. CSS Checker will then quickly figure out all the unused styles that you may safely discard or move to another CSS file.
CSS Compressor - This is pretty much like Clean CSS though you have more control over handling of comments and new lines in the optimized version of the CSS.
Unlike Clean CSS, the CSS Compressor tool can’t pull your CSS files - you need to copy-paste the CSS code in the text area.
Related: How to Completely Test Your Website
Google Developer Expert, Google Cloud Champion
Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.