Selectors

suggest change

Selectors 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;
}

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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents