CSS Efficiency
Considering how much CSS I write on a daily basis, I never wondered what is the fastest way to render the CSS I produce, and what are the costs in CPU and load time.
Chris Coyier did a nice research explaining what are the most fast and efficient selectors in CSS, and I’ll summarize his findings here.
- Right to Left — Browsers read you selectors from right-to-left, i.e. if you have a selector as such:
ul > li a[title="home"]the browser will first look for an elementawith the attribute title equal tohomeand only then check if it’s a descendant of anlitag. - ID’s are the most efficient selectors, universal selectors are the least efficient.
- Tag qualifying (
ul#navigation)is very inefficient, don’t use them. - Descendant selectors (
html body ul li a) are efficiency disaster as Chris puts it.
To read the rest of the article I suggest you visit css-tricks.com, worth the read.
/e.s

