Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS selector performance

Tags:

css

I know the performance difference is miniscule, but which is a faster CSS selector?

div.class{ }

or

.class{ }
like image 260
siliconrockstar Avatar asked Dec 27 '22 05:12

siliconrockstar


1 Answers

CSS Selectors are parsed right to left, and then displayed, and the full rule is always parsed. So that would lead me to believe that .class is slightly quicker than div.class. That said, there's also the time taken to render the page, so it may depend on how many elements have that class and how complex the rule is.

Now with all of that said, check out the first answer here: https://softwareengineering.stackexchange.com/questions/80084/is-premature-optimization-really-the-root-of-all-evil

like image 105
Chris Sobolewski Avatar answered Jan 16 '23 05:01

Chris Sobolewski