Search⌘ K

Pseudo-Classes in CSS

Explore how pseudo-classes in CSS apply styles based on element states to improve interactivity and layout design. Understand the common pseudo-classes like :hover and how to use ::before and ::after pseudo-elements to add content and manage layout effects such as clearfix.

What are pseudo-classes?

A pseudo-class describes how a selector should look when in a special state.

The most common special state for any element is its hover state, and therefore, the pseudo-class of :hover is most commonly used.

Let’s consider an example:

Note: The colon : is used to separate a property from its value, while the space is used to indicate a descendant selector or a combinator. That's why body : ...