CSS Selector List Grouping (,)

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

A selector list is a comma-separated group of selectors that share one declaration block. When several selectors need the same styles, list them once instead of repeating the rule.

Example: h1, h2, h3 { color: navy; } is the same as three separate rules with identical declarations. Spaces around the comma are optional.

Baseline Widely available.

Selector lists are a core CSS feature, long supported in all major browsers.

Warning — one bad selector can drop the whole rule.

If any selector in a normal list is invalid, the browser ignores the entire block. Forgiving lists inside :is() / :where() keep valid selectors working.

CSS Syntax

syntax.css
selector1 , selector2, … { … }

Equivalent to writing each selector in its own rule with the same declarations.

Selector Patterns

PatternDescriptionTry it
h1, h2, h3Group heading types with one ruleTry it
.a, .bShare styles across classesTry it
multi-line listOne selector per line for readabilityTry it
mixed selectorsCombine id, class, and type selectorsTry it
vs separate rulesSame result as repeating declarationsTry it
with combinatorsGroup complex selectors tooTry it

How to Use Selector Grouping

Group only when the declarations are truly the same.

  1. Find selectors that need identical styles.
  2. List them separated by commas.
  3. Write the shared declarations once in the block.
  4. Keep each selector valid — one bad item can drop the whole rule.
PieceRequired?Role
Two or more selectorsYes (for a list)Each matches independently
CommaYesSeparates selectors in the list
Shared declarationsYesApplied to every match in the list
Valid selectors onlyYesOne invalid selector can invalidate the rule

Live Preview

Switch grouping patterns and watch which elements pick up the shared style.

Matched items get a shared accent color from the grouped rule.

Grouping preview

Heading 1 / #hero

Heading 2 / .title

Heading 3

Paragraph / .card

Paragraph / .note

Rule: h1, h2, h3 — headings match

CSS Examples

Each snippet focuses on comma grouping. Use Try It Yourself for a live editor.

Example 1 — Group Heading Types

One rule for several heading levels.

CSS
h1, h2, h3 {
  color: #1e3a8a;
  font-family: Georgia, serif;
}
Try It Yourself

How It Works

  1. List the selectors. h1, h2, and h3 are separated by commas.
  2. Share one block. Color and font apply to every match.
  3. Skip other elements. A p is not in the list, so it stays unchanged.
  4. Same as three rules. Grouping only removes repetition.

Example 2 — Group Classes

Share a look across different class names.

CSS
.card, .note {
  color: #1d4ed8;
  font-weight: bold;
}
Try It Yourself

How It Works

  1. Name each class. .card and .note are listed together.
  2. Apply shared styles. Both become bold blue.
  3. Leave others alone. Elements without those classes do not match.
  4. Keep names clear. Grouping does not merge the classes in HTML.

Example 3 — Multi-Line List

Put each selector on its own line for easier reading.

CSS
#main,
.content,
article {
  font-size: 1.1em;
}
Try It Yourself

How It Works

  1. Stack the list. One selector per line, commas between them.
  2. Mix selector types. Id, class, and element can sit in one list.
  3. Share declarations. Font size applies to every match.
  4. Read easily. Multi-line lists are easier to scan and review.

Edge Cases & Pitfalls

Most grouping bugs come from invalid list items or mixing unrelated styles.

invalid

One invalid selector drops the rule

In a normal list, a typo or unsupported selector invalidates the whole block. Split rules or use :is() / :where() for forgiving lists.

not &

Comma is not a combinator

h1, p does not mean “p inside h1.” For relationships, use space, >, +, or ~.

same styles

Only group identical declarations

If two selectors need different values, keep separate rules. Grouping forces one shared block.

specificity

Each selector keeps its own specificity

Grouping does not average specificity. #id, .class still compete as id vs class when they match the same element.

space

Spaces around commas are optional

h1,h2 and h1, h2 are both valid. Prefer a space after the comma for reading.

Browser Support

Selector list grouping is a browser CSS feature. Node.js, Deno, and Bun do not evaluate selector lists.

✓ Baseline · Widely available

Selector list (,)

Supported in all major browsers for decades (Baseline Widely available since about July 2015).

99% All modern browsers
Google Chrome All
Full
Mozilla Firefox All
Full
Apple Safari All
Full
Microsoft Edge All
Full
Opera All
Full
Samsung Internet All
Full
Internet Explorer All
Full
sel1, sel2 Universally supported

Bottom line: Production-ready. Watch for invalid selectors in a list. Not a server runtime API.

Key Takeaways

  • Role: share one declaration block across many selectors.
  • Form: sel1, sel2, sel3 { … }
  • Not a combinator: commas do not describe parent/child relationships.
  • Tip: keep every list item valid, or use forgiving :is() / :where().

One line: A, B, C { … } applies the same styles to every matching selector.

Frequently Asked Questions

A selector list is a comma-separated list of selectors that share one declaration block. Example: h1, h2, h3 { color: navy; } styles all three heading types.
No. Combinators like space, >, +, and ~ describe relationships between elements. A comma only groups independent selectors into one rule.
In a normal rule, one invalid selector makes the whole rule fail. Separate rules, or forgiving lists inside :is() / :where(), keep the valid selectors working.
Yes. Lists can mix any selectors: #hero, .card, article { … }.
Optional. Single-line and multi-line lists are both valid. Multi-line lists are easier to read and review in git diffs.
No. It is a browser CSS selector-list feature, not a Node.js API.

Next: :active

Style an element while it is being activated (for example, during a click).

:active tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful