Skip to main content
D
CSS
CSS Pseudo-Classes

CSS Pseudo-Classes

CSS pseudo-classes style elements based on their current state.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

CSS pseudo-classes change an element's appearance when a user interacts with it. A common example is changing a button's color when the mouse hovers over it. They attach to regular selectors using a single colon.

Syntax

Syntax
1/* pseudo-class syntax */
2selector:pseudo-class {
3  property: value;
4}

Example

Example
1/* this changes color on hover */
2button:hover {
3  background-color: green;
4}

Key Points

  • Pseudo-classes reflect user interactions.
  • The `:hover` pseudo-class triggers on mouse over.
  • The `:focus` pseudo-class triggers when clicking an input field.
  • The `:nth-child()` pseudo-class targets specific items in a list.

Up Next

Continue your journey with the next topic.

Go to CSS Pseudo-elements