CSS: Pseudo-classes & Pseudo-elements

Learn how to use pseudo-classes and pseudo-elements to style specific parts of elements.

Pseudo-classes

Pseudo-classes allow you to style elements based on their state or position:

Pseudo-elements

Pseudo-elements allow you to style specific parts of an element:

Example: Pseudo-classes & Pseudo-elements

/* Example */
a:hover {
    color: red;
    text-decoration: underline;
}
p::first-line {
    font-weight: bold;
    color: blue;
}
        

This example changes the color and style of links on hover and styles the first line of a paragraph.

Practice

Try experimenting with pseudo-classes and pseudo-elements:

Continue Learning

Quick Check

Which pseudo-class styles a link when the mouse pointer is over it?