How to Optimize CSS Selectors for a Faster Website
March 16th, 2010 by
Browsers render optimized style sheets faster than messy ones.
Therefore, making your CSS code as short and clean as possible is an efficient method to improve page loading time.
To make your CSS short and clean, you need to remove redundant selectors carefully, in a way that will not impact your site design.
The safest way to do that, would be to test all changes on a test environment, set locally using site backup, and only then implement them to the live site.
However, If you don’t want to install your website locally and prefer the shorter way, simply copy the website directory (if WordPress, copy your theme folder) to your local computer.
Take the following steps to clean your CSS:
- Open Dreamweaver and define a site. It’s simple and extremely helpful. Make sure to assign your backup directory as the Local Root Folder.
- Open your main stylesheet in DreamWeaver and go over it.
- Remove the global resetting
*{padding:0;margin:0}if you have one. The star selector makes browsers go over all the elements in the current page and is very inefficient.
Instead, reset only selectors you need to, such as H1, H2, ul, p, form etc. (e.g.H1, H2, ul, p, form{padding:0;margin:0}). - Go over the definitions and delete unnecessary selectors.
For example: replaceh4.meta{}with.meta{}, unless you use the class “meta” inside a different tag in your site.
Now that your local site is defined in DreamWeaver, you can make sure of it by searching for all appearances of class=”meta” site wide. - Click CTRL + F and follow the instructions below:

Take a look at the search results in the image above.
As can see, all appearances of class=”meta” are inside the h4 HTML tag.
This means that h4 is redundant in theh4.meta{}CSS definition, and so, you can use.meta{}instead.
If there were several different HTML tags in which class=”meta” appeared, then leavingh4.meta{}would be correct, but this is not the case. - In case you have a chain of three or more selectors in a row. Define new IDs or classes to break the long chain.
For example, the definition#main_content div ul li{}is too long. Add a unique ID to the ul tag and then change the definition to be called by the new ID (e.g.#postList li{}) - Avoid using CSS !important override property unless you really have to.
- Remove the global resetting
- Finally, compress your CSS code using an online css compressor to decrease file size.




Amazing suggestion! My website could use a revamp or two, but I wouldn’t have to worry about optimizing it. I got http://www.mroptimization.com to help me with that, but I also believe website design is a big thing
Omer great write up. I just recommend this to one of my clients to help speed up their site. I didn’t get the chance to work with the client on that project, but its about time to start cleaning my CSS and remove all the useless code.
Thanks man. Another thing I recently learned about CSS: EMs are no longer necessary for font-sizes and other elements as they were before, and it’s recommended to go back to pixels for better rendition.
That good. When I am creating from scratch, I tend to use pixels.
By the way, ems are faster for development when you need to change all typography on a site. You just change your base font size definition. Pixels are not guaranteed. If you change the resolution settings in Windows from 92/inch to 126/inch, you will get a nasty surprise if everything you develop is pixel based.
How did you measure this to be “faster”?
Your conclusions are wrong. Using “.meta”, a browser will scour the DOM for EVERY element and then test the class for a match. Using “h4.meta”, the browser will only test the h4 elements.
Hi @None – when using h4.meta the browser search for all h4 tags (which is not necessary less time than searching for the meta class) and then, in addition, it will activate a second filter of class meta. This 2 actions will take longer to process than just looking for all meta class objects.
Regarding EMs vs Pixels. I’m not sure which resolution change you refer to in that example, but pixels are the native measurement unit in which the browser renders, so using EMs will always take a bit longer than using pixels because it adds a conversion task to the browser rendition.