CSS Selectors
What are CSS Selectors?
CSS selectors are used to target and select HTML elements so that styles (CSS rules) can be applied to them.
They act like a bridge between your HTML structure and your CSS styling.
👉 Example:
p {
color: blue;
}
This selector targets all <p> elements and makes their text blue.
Types of CSS Selectors
CSS selectors are mainly divided into 5 categories:
- Simple selectors (select elements based on name, id, class)
- Combinator selectors (select elements based on a specific relationship between them)
- Pseudo-class selectors (select elements based on a certain state)
- Pseudo-elements selectors (select and style a part of an element)
- Attribute selectors (select elements based on an attribute or attribute value)