Vandervals
Vandervals

Reputation: 6054

Does * selector affect performance seriously?

Sometimes i find very usefull doing this:

.someclass > *{}

to select all the direct children of an object. Problem is that I read that selectors get evaluated from right to left so that is telling to get every html element from the begining and then filter. Can this cause serious performance issues if done multiple times?

I also do this for my css reset:

*, *:after, *:before{}

EDIT: Is there a way to select all direct children without using the * selector?

Upvotes: 2

Views: 1496

Answers (1)

Alex Macra
Alex Macra

Reputation: 177

This is a very un-performant selector, but actually the performance impact is negligible. That is, of course without using properties like box shadows, animation on the universal selector. That will actually slow down the site as well.

So, if you know what you're doing, you can use the universal selector, but if you like to optimize your site performance best as possible, I would recommend you to avoid using it.

Upvotes: 4

Related Questions