The CSS selectors :where()
and :is()
are two pseudo-classes that allow you to select elements based on their relationship with other elements. Although they sound similar, they are different in terms of functionality and syntax.
Your Web Designer Toolbox
Unlimited Downloads: 500,000+ Web Templates, Icon Sets, Themes & Design Assets
The :where()
pseudo-class was introduced as part of the CSS Selectors Level 4 specification and allows you to select elements based on the presence of other elements that match a specific condition. In other words, you can select elements based on the relationship between elements in a DOM tree. For example, you can use the :where()
selector to select a list item li
only if it is the first child of an unordered list ul
:
li:where(:first-child of ul) { background-color: yellow; }
On the other hand, the :is() pseudo-class is part of the CSS Selectors Level 3 specification and allows you to select an element if it is one of several different selectors. It is similar to the logical OR
operator, in CSS. For example, you can use the :is()
selector to select a p
element if it is either the first child of its parent or has a class of highlight
:
p:is(:first-child, .highlight) { background-color: yellow; }
It’s important to note that the :where()
selector has better browser support than the :is()
selector, and that the :is()
selector should not be used in conjunction with the :not()
pseudo-class.