ID Selector (#)
W3C CSS Snapshot 2026
Use # before an ID. Give each ID to just one element in the document.
On this page
Syntax and values
| Value or syntax | What it does |
|---|---|
#location | Matches the element with id="location". |
p#location | Matches that ID only if the element is a paragraph. |
Try the example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ID Selector (#)</title>
<style>
#location { color: teal; font-weight: bold; }
</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 Only the room location changes.