- Home
- /
- CSS Selectors
CSS Tutorial
Introduction
CSS Properties
CSS Designing
CSS Advance Topics
CSS FAQs
- Home
- /
- CSS Selectors
CSS Selectors
What are CSS Selectors?
CSS selectors are used to select specific HTML elements and apply styles to them. Instead of styling every element manually, selectors allow us to target elements efficiently using tag names, classes, IDs, or more.
Types of CSS Selectors
There are five major types of selectors you should know:
- Universal Selector
- Element Selector
- ID Selector
- Class Selector
- Group Selector
Let’s explore each one with examples.
Universal Selector
What it does:
Applies the given styles to all HTML elements on the page.
Syntax
* {
property: value;
}
Example
Welcome to
Learn With Arshyan
Result:

Both <p>
and <h1>
will be purple and centered – regardless of tag.
Element Selector
What it does:
Targets all elements of a specific tag name like p
, h1
, div
, etc.
Syntax
p {
property: value;
}
Example:
CSS
Welcome to Learn With Arshyan
we offer:
HTML – Tutorial
CSS – Tutorial
Result:

All <p>
tags will be underlined.
Note: Be cautions – if a tag is used many times, styles may apply more broadly than expected.
ID Selector
What it does:
Target a single unique element by its id.
Syntax:
#idName {
property: value;
}
Example:
Learn With Arshyan /
I'm a Developer and the founder of learnwitharshyan.com
Result:

Only the element with id= “title”
is affected.
Tip: Use ID selectors when styling a single, unique element.
Class Selector
What it does:
Targets one or more elements with a shared class time.
Syntax:
.className {
property: value;
}
Example:
CSS
This is simple p tag
This p tag has class purple
This is simple p tag
This p tag has class purple
Result:

Only elements with class = “purple”
are affected.
Tip: Use class selectors when multiple elements need the same style.
Group Selector
What it does:
Targets multiple selectors at once to apply the same styles. Saves time and keeps code clean.
Syntax:
h1, p, a {
property: value;
}
Example:
CSS
Learn With Arshyan
This is the p tag
This is the anchor (a) tag
Result:

<h1>
will be purple.- Both
<p>
and<a>
will be black.
Summary Table
Selector Type | Symbol | Use Case |
Universal |
| Apply style to every element |
Element (Tag) |
| Style all specific tag elements |
ID Selector |
| Style one unique element by ID |
Class Selector |
| Style multiple elements with a class |
Group Selector |
| Combine multiple selectors in one rule |