TLDR
- Always use
:is
, never use:where
- The only exception is that if you are writting your own “CSS Reset” file, then you may use
:where
.
Similarities
Both :is
and :where
peseudo selector matches element based on a list of selectors, they allow you to group selectors together and apply styles to any element that matches any of the selectors in the list. For instance imagine we have multiple <input>
child component wrapped in two different <form>
parent comopnent, and we want to select them all based on their the form’s classname and input’s type attribute.
|
|
Difference
The difference between the two functional Pseudo-Classes is the specificity:
:is
will add the same specificity as its inner most specific selector (within the bracket) to the overall selector:where
contribute no specificity (irrelevant of the selector within the bracket) to the overall selector, which can be useful when you want to apply styles to a group of elements without increasing the specificity.
For instance:
|
|
|
|
And as a result they will appear different usecases, which is explained well in this post.