:is() Pseudo-class in CSS

By Hemanta Sundaray on 2021-07-09

The CSS :is pseudo-class is useful for writing large selectors in a more compact form.

The :is() function takes a selector list as its argument, and selects any element that can be selected by one of the selectors in that list.

Below, we have an App component.

import React from "react"

const App = () => {
  return (
    <div className="wrapper">
      <header>
        <p>Header</p>
      </header>
      <main>
        <p>Main Content</p>
      </main>
      <footer>
        <p>All Rights Reserved</p>
      </footer>
    </div>
  )
}
export default App

We can style the paragraphs inside the header, main and footer tags as follows:

header p,
main p,
footer p {
  font-size: 1.4rem;
  font-weight: 700;
  color: gray;
}

This is the usual approach. However, we can write our selectors in a more compact form using the :is pseudo-class as follows:

/* Selects any paragraph inside a header, main or footer tag. */

:is(header, main, footer) p {
  font-size: 1.4rem;
  font-weight: 700;
  color: gray;
}

Join the Newsletter