# CSS Pseudo-Class

> A bit of a CSS rule that picks a thing by its state. :hover means the mouse is on it.

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** Pseudo-Class, :hover, :focus, Pseudo Class Selector

## Think of it like

It is like a light that comes on when someone stands at the door.

## Definition

A CSS pseudo-class picks an element by its state or place, not by its name. It starts with one colon. :hover matches while the mouse is over the element, and :focus matches the box being typed in. :first-child matches the first item in a list. A pseudo-class counts like a class when the browser scores which rule wins.

## Example

Lucy wants her buttons to turn dark when the mouse is on them. She adds one rule with button:hover, and no JavaScript.

## Example code

```css
button:hover { background: navy; }
input:focus { outline: 2px solid teal; }
```

The button goes dark under the mouse. The box being typed in gets a teal ring.

## Why it matters

It lets a page answer the reader with no script at all. Clear focus styles also help people who use a keyboard.

## Common mistake

Mixing it up with a pseudo-element, like ::before. A pseudo-class has one colon and picks a state; two colons make a new part.

## Three principles

- **One colon.** :hover, :focus, :first-child.
- **State or place.** It picks by what is happening.
- **Scores as a class.** It adds 0-1-0 to the score.

## Related terms

- [CSS Selector](https://learn.benibix.com/term/development/css-selector)
- [CSS Specificity](https://learn.benibix.com/term/development/css-specificity)
- [Cascading Style Sheets (CSS)](https://learn.benibix.com/term/development/css)
- [Browser Event](https://learn.benibix.com/term/development/browser-event)
- [CSS Transition](https://learn.benibix.com/term/design/css-transition)

## Taught in

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

![A table with three columns, ID, CLASS and TYPE, and four selectors. p scores 0-0-1. .note scores 0-1-0. a:hover scores 0-1-1, since the pseudo-class counts as a class. #intro .note p scores 1-1-1 and is marked the winner, since the left column is compared first.](https://learn.benibix.com/diagrams/dev5-specificity.svg)

---

Source: https://learn.benibix.com/term/development/css-pseudo-class
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.
