Selector List (,)

W3C CSS Snapshot 2026

Separate selectors with commas to apply one rule to anything that matches any selector in the list.

On this page

Syntax and values

Value or syntaxWhat it does
h2, .noticeMatches all h2 elements and all elements with class notice.
h2.noticeMatches only an h2 that also has class notice.

Try the example

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Selector List (,)</title>
  <style>
h2, .notice { color: teal; }
  </style>
</head>
<body>
<p class="notice">Registration opens Monday.</p>
<p id="location">Meet in Room 2.</p>
<h2>Workshop</h2>
</body>
</html>

What to expect The heading and notice change color. Remove the comma to see the difference.

Official references