If we wanted to target a link within a paragraph, which selector would be more efficient/faster?
p a
or
p > a
If we wanted to target a link within a paragraph, which selector would be more efficient/faster?
p a
or
p > a
The second is (extremely) marginally faster. CSS is handled in reverse by browsers, so both your rules are tested on all a
elements on the page. For the second rule it only needs to test the direct parent, for the other one it would need to test the entire descendant chain.
In practice, the execution time difference won't be statistically significant until you get tens of thousands of these on a page with just as many lines of HTML.
Let me show you the efficiency order of selectors, from fastest to the slowest, that's some conclusion from google:
It might not be exactly right, and not being right for various of browsers, but still this order is available for reference. Hope it helps!
To see more about CSS performance, see: http://benfrain.com/css-performance-revisited-selectors-bloat-expensive-styles/