Class Selector (.)

W3C CSS Snapshot 2026

Use a dot before a class name. You can reuse a class on several elements and give an element several classes.

On this page

Syntax and values

Value or syntaxWhat it does
.noticeMatches an element with notice in its class list.
p.noticeMatches paragraphs with the notice class.
.notice.urgentMatches elements that have both classes.

Try the example

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Class Selector (.)</title>
  <style>
.notice { color: teal; }
.notice.urgent { font-weight: bold; }
  </style>
</head>
<body>
<p class="notice urgent">Bring your ID.</p>
<p class="notice">Doors open at 9.</p>
<p>Parking is free.</p>
</body>
</html>

What to expect Two paragraphs turn teal. Only the paragraph with both classes is bold.

Official references