To improve the performance of the example above, we could replace .container ul li a with adding something like .container-link-style on the <a> tag itself.
Things nobody ever taught me about CSS.
Charlie Gerard
8.5K31

2 things:

  1. This proposed approach pollutes your HTML with super specific classes and defeats the point of Cascading Style Sheets, i.e. they should cascade/inherit! Assuming a rigid structure (which is likely) then you should use the child selector, i.e. “.container > ul > li > a”
  2. More fundamentally, selector performance isn’t something you should worry about — see https://benfrain.com/css-performance-revisited-selectors-bloat-expensive-styles/ — but of course if you can be more precise (as above) then you should.