# CSS Selector

> The part of a CSS rule that says which parts of the page it styles.

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** Selector, CSS Selectors, Class Selector

## Think of it like

Think of it like calling out in a classroom. Everyone in red, stand up.

## Definition

A CSS selector picks which elements a style rule applies to. A tag name like p picks every paragraph. A dot and a name, like .nav, picks each element with that class. A hash and a name, like #logo, picks the one element with that id. You can join selectors to pick more closely, like each link in the menu.

## Example

Lucy writes .price { color: red; }. Every element on her shop page with the class price turns red at once.

## Example code

```css
nav a {
  color: teal;
}
```

This picks only the links that sit inside a nav element.

## Why it matters

Every style on a page reaches its target through a selector. A wrong one styles too much, or nothing at all.

## Common mistake

Using id selectors for styles you want to reuse. An id is for one element, so use a class instead.

## Three principles

- **Tag, class or id.** p, .name and #name pick in different ways.
- **Join to narrow.** nav a picks only links in the menu.
- **Classes reuse best.** One class can style many elements.

## Related terms

- [Cascading Style Sheets (CSS)](https://learn.benibix.com/term/development/css)
- [HTML Attribute](https://learn.benibix.com/term/development/html-attribute)
- [HTML Element](https://learn.benibix.com/term/development/html-element)
- [Document Object Model (DOM)](https://learn.benibix.com/term/development/dom)
- [Tailwind CSS](https://learn.benibix.com/term/development/tailwind-css)
- [CSS Pseudo-Class](https://learn.benibix.com/term/development/css-pseudo-class)
- [CSS Specificity](https://learn.benibix.com/term/development/css-specificity)

## Taught in

- [CSS Selectors and Specificity](https://learn.benibix.com/learn/development-web/css-selectors-and-specificity): HTML, CSS and JS, 7/14

![The line <a href="/about" class="nav">About us</a> with its parts marked: the opening tag with two attributes, the content About us, and the closing tag. Under it, href="/about" is marked as an attribute, name equals value, saying where the link goes. class="nav" is marked as a label that CSS can find. An arrow runs up to it from the CSS rule .nav { color: teal; }.](https://learn.benibix.com/diagrams/dev-html-anatomy.svg)

---

Source: https://learn.benibix.com/term/development/css-selector
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
