The :is()
pseudo-class is particularly useful when dealing with HTML sections and headings. Since <section>
, <article>
, <aside>
, and <nav>
are commonly nested together, without :is()
, styling them to match one another can be tricky.
For example, without :is()
, styling all the h1 elements at different depths could be very complicated:
h1 {
font-size: 30px;
}
section h1,
article h1,
aside h1,
nav h1 {
font-size: 25px;
}
section section h1,
section article h1,
section aside h1,
section nav h1,
article section h1,
article article h1,
article aside h1,
article nav h1,
aside section h1,
aside article h1,
aside aside h1,
aside nav h1,
nav section h1,
nav article h1,
nav aside h1,
nav nav h1 {
font-size: 20px;
}
Using :is()
, though, it's much easier:
h1 {
font-size: 30px;
}
:is(section, article, aside, nav) h1 {
font-size: 25px;
}
:is(section, article, aside, nav) :is(section, article, aside, nav) h1 {
font-size: 20px;
}
:is(section, article, aside, nav)
:is(section, article, aside, nav)
:is(section, article, aside, nav)
h1 {
font-size: 15px;
}