DEV Community

Discussion on: CSS :not Selector

Collapse
 
gmartigny profile image
Guillaume Martigny

Nice post.

I just want to add one caveat of the :not selector:
It's quite expensive when working on low-performance environment. (let's be clear, I'm not talking about regular personal computer.)

CSS parse selector from right to left. So for this :

li:not(:first-of-type) {
}
Enter fullscreen mode Exit fullscreen mode

The parser will select all nodes being :first-of-type (potentially a lot). Then apply the inverse with the :not, and finally keeping only the li tag among them.

Given :not is never the only way to do something in CSS, if you really care for performance, avoid the :not selector. (in the end, it's very useful and I use it on personal projects)

Collapse
 
samanthaming profile image
Samantha Ming

Very good point! Something to definitely keep in mind when choosing what kind of CSS selector to use. Thanks for sharing this insight 👍