How to Select Elements by Tag Name in CSS
A type selector styles every element of one kind: write the tag name on its own. p { ... } styles every paragraph on the page.
Syntax
<element name> {
<declarations>
}
| Part | What it does |
|---|---|
<element name> | The tag name without the angle brackets, such as p for paragraphs. |
<declarations> | The styles every element of that kind gets. |
MDN's Type selectors page explains that a type selector selects all elements of the given type in the document.
The Example
The example is a page of opening hours: a heading and two paragraphs. One rule colors every paragraph grey.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Type selector</title>
<style>
p {
color: #616161;
}
</style>
</head>
<body>
<h1>Opening hours</h1>
<p>Monday to Friday, 9:00 to 17:00.</p>
<p>Closed on public holidays.</p>
</body>
</html>
The selector p matches every p element, so both paragraphs get the color #616161.
Step 2: Open It in a Browser
Double-click index.html. It opens in your browser:

The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.
What Happened
- Both paragraphs are grey. Chromium gave them the color
rgb(97, 97, 97), which is#616161. - The heading stayed black. It's an
h1, not ap.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Writing the angle brackets: <p> | <p> isn't a valid selector, so Chromium dropped the rule and the paragraph stayed black | Write only the name: p |
Adding a dot: .p | The dot makes it a class selector for class="p", which no element had | Leave out the dot |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Nothing changes | The selector has angle brackets or a dot | Write the bare tag name |
| Elements you didn't mean to style changed | A type selector matches every element of that kind | Give the ones you want a class, and select the class |
FAQ
Does the case of the tag name matter?
Not in an HTML page: P styled the paragraph just like p.
How do I style only some of the paragraphs?
Give those paragraphs a class in the HTML and select the class with a dot, such as .note. A type selector always matches all of them.
Conclusion
Write the tag name on its own, with no brackets and no dot, and the rule styles every element of that kind on the page.
Additional Resources
- Type selectors, on MDN.
