CSS :is Selector
Complete CSS Selector Reference Manual
Example
We want to apply styles to elements that contain set the color for tags:
:is
(
p
)
{
color:
red
;
}
Try it »
Definition and usage
The CSS :is pseudo-class is a generic selector that allows you to combine multiple selectors together so they can be reused in CSS rules.
:is The pseudo-class can accept any number of selectors as arguments and returns the union of the elements matched by those selectors.
1. Combining element type selectors
:is(h1, h2, h3) {
color: red;
}
This code sets the text color of all h1, h2, and h3 elements to red.
** 2. Combining class selectors**
:is(.highlight, .warning) {
font-weight: bold;
}
This code sets the font weight to bold for all elements with the highlight or warning class.
3. Combining different types of selectors
:is(a[href^="https"], button[disabled]) {
cursor: pointer;
}
This code sets the mouse cursor to a pointer for all links starting with https and buttons in the disabled state.
Note
:isThe pseudo-class can improve the readability and maintainability of CSS code, especially when you need to apply the same styles to multiple types of elements.:isThe pseudo-class does not create new elements or change the document structure; it is merely a selector used to match elements.
Browser support
The numbers in the table indicate the first browser version that supports this property.
| Selector | |||||
|---|---|---|---|---|---|
| :invalid | 10.0 | 10.0 | 4.0 | 5.0 | 10.0 |
CSS Syntax
:is(selector1, selector2, ..., selectorN) {
/* Style rules */
}
selector1, selector2, ..., selectorN: this is a series of selectors, which can be element types, class selectors, attribute selectors, pseudo-classes, etc.