Skip to content
BENIBIX Learn

CSS Selector

Development🌐 Web DevelopmentBrowser Code

Also known as Selector, CSS Selectors, Class Selector

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

Think of it like

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

Example

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

Why it matters

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

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 code

css
nav a {
  color: teal;
}
This picks only the links that sit inside a nav element.
The selector .nav, in the box at the bottom, picks the link by its class.

Common mistake

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

Key takeaways

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

Learn it properly