Selectors
suggest changeSelectors match elements to which a style rule applies:
article { } /* Type selector */
.card { } /* Class selector */
#main { } /* ID selector */
[aria-current="page"] { } /* Attribute selector */
nav > a { } /* Child combinator */
a:hover { } /* Pseudo-class */
li::marker { } /* Pseudo-element */
Modern functional pseudo-classes make selector lists more expressive:
:is(h1, h2, h3) > a {
color: inherit;
}
:where(header, main, footer) a {
text-underline-offset: 0.15em;
}
.field:has(> input:invalid) {
border-color: crimson;
}
.item:not(:last-child) {
margin-block-end: 1rem;
}
:is()matches any selector in its list and takes the specificity of its most specific argument.:where()behaves similarly but always has zero specificity.:has()matches an element according to relative selectors anchored against it.:not()excludes matches and accepts a selector list.
Prefer classes and low-specificity selectors for reusable components. IDs are appropriate for document identifiers and fragment links but often make style overrides unnecessarily difficult.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents