DEV Community

Cover image for What is the use of ':is()' in CSS?
StakeDesigner
StakeDesigner

Posted on

What is the use of ':is()' in CSS?

The "is" selector in CSS is a type of pseudo-class that allows you to select elements that are in a specific state. This state could be a hover state, an active state, or a focus state, among others. In other words, the "is" selector helps you apply styles to elements based on the way they are being interacted with by the user.

Here's an example of how you can use the "is" selector in CSS:

Image description

In this example, the "is" selector is being used to select the button element when it's being hovered over and activated at the same time. The background-color property is then set to blue to change the color of the button when these conditions are met.

The "is" selector can also be used in combination with other selectors to target specific elements with greater precision. For example:

Image description

In this example, the "is" selector is being used to select p elements that have the class highlight. The background-color property is then set to yellow to give these elements a yellow background.

It's important to note that the "is" selector is only supported in modern browsers, so you should use it with caution and make sure to provide fallback styles for older browsers.

In conclusion, the "is" selector in CSS is a powerful tool that can be used to apply styles to elements based on their state. Whether you're styling buttons, links, or other elements, the "is" selector can help you create dynamic and interactive user interfaces with ease.

💡 NOTE: If you can't see it click here and see the final result

Support

YouTube
Website

Thanks for reading!

If you have any questions, complaints or tips, you can leave them here in the comments. I will be happy to answer!

😊😊 See you later! 😊😊

Top comments (3)

Collapse
 
mackfitz profile image
Maciek Fitzner

:is is a ton of fun, I use it a lot. It is a pity you can't use it to target pseudo-elements - the ::before and ::after. Oh well. Also, there's :where - which does basically the same thing, but has lesser specificity. When :is overrides other styles that target the same element and you don't want that, :where is a godsend.

Collapse
 
codeofrelevancy profile image
Code of Relevancy

Great article for UI designer..

Collapse
 
stakedesigner profile image
StakeDesigner

Thank you