CSS Reference ยท Selectors
Selector lists (A, B)
Reference for CSS selector lists: group selectors with commas to share one declaration block, and how forgiving selector lists in :is() and :where() behave.
A selector list is two or more selectors separated by commas. The declaration block applies to every element matched by any of them. Each selector keeps its own specificity, so the list is just a shorthand for writing the same rule several times.
h1, h2, h3 { font-family: Georgia, serif; }
Try it
Syntax and arguments
A, B, C { } /* the rule applies to A, B and C */ :is(h1, h2) span { } /* forgiving list inside :is() */ :where(ul, ol) li { } /* same, with zero specificity */ :has(> img, > video) { } /* forgiving in :has() too */
| Form | Description |
|---|---|
A, B |
A standard (unforgiving) list. If one selector is invalid, the whole rule is dropped. |
| Forgiving list | Inside :is(), :where() and :has(), an invalid selector is ignored and the valid ones still work. |
| Trailing comma | A, B, { } is invalid in a normal rule. |
Each selector in a list has its own specificity. With h2, #special, an h2 element gets 0,0,1 and the element with the ID gets 1,0,0. Inside :is() the whole function takes the specificity of its most specific argument, while :where() always counts as zero.
Usage notes
- One typo ruins the rule.
h1, h2, :unknown-pseudo { }is discarded entirely by browsers that do not know:unknown-pseudo. This is the main reason to avoid mixing new and old selectors in a single list. - Vendor-prefixed selectors. Split them into separate rules (for example
::-webkit-...versus the standard form), or one failing selector will take down the others. - Shorter nested code.
:is()removes repetition::is(.a, .b) :is(h1, h2)replaces four selectors. See:is(). - Whitespace and newlines. Put each selector on its own line in long lists. They are free to contain any amount of whitespace.
- Order does not matter. The list is a union; the cascade still decides conflicts using each selector's specificity and the rule's position.
- In nesting. Inside a nested rule,
&is replaced with the whole parent list, treated as if wrapped in:is(). See nesting.
Browser support
Standard selector lists work everywhere. Forgiving parsing inside :is() and :where() is supported in all current browsers.