Yogesh Chauhan's Blog

Difference between :where and :is in CSS

in CSS on July 22, 2021

Here’s another post covering basics of :is pseudo selector:

Does :is() pseudo selector hint at CSS preprocessing in future?

where()

:where() is a pseudo-class function that accepts a selector list argument and appys the style to whichever selector matches.


:where(div, main, section) p {
  font-size: 1rem;
}

Which is same is using :is as we saw in the :is() pseudo selector post.

DIFFERENCE

:where() has 0 specificity, always.

:is() has the specificity of the selector in its arguments.

Example

Here is one simple example in which the :where pseudo-class style is overridden by another style rule, which is added afterwards and that’s why it overrides the specificity of :where (0).

BUt if I change the order of the style rules, it will work:


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
KeyValuePipe in Angular 9AngularHow to zoom an element on hover using CSS?CSSA few HTML coding standards from WordPressHTMLHow to detect the Blog Page in WordPress?WordPressA complete diagram with building blocks of an Angular applicationAngularCreate a currency (dollar) to coins convertor in ReactReactWindow innerHeight and innerWidth properties in JavaScriptJavaScriptGeneral concepts in DrupalDrupalWhat are Class Constants in PHP?PHPHow to create a dynamic countdown using HTML and JavaScript?HTMLHow to display modal from bottom to top using CSS and JavaScript?CSSHow to auto-resize textarea based on text input using JavaScript or jQuery?JavaScript