What are pseudo-classes and pseudo-elements in CSS?

A pseudo-class (one colon) selects an element in a special state or position. A pseudo-element (two colons) selects a part of an element, or adds content.

a:hover { color: red; }              /* pseudo-class */
li:nth-child(odd) { background: #eee; }

p::first-letter { font-size: 2em; }   /* pseudo-element */
.price::before { content: "$"; }

See Pseudo-classes and pseudo-elements.


Learn more about the similar topics:
Tutorials
CSS Selectors
CSS Specificity
CSS Pseudo-classes and Pseudo-elements
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is the CSS class selector?
What is grouping in CSS and what is it used for?
What are child selectors in CSS?
What is the difference between id and class selector in CSS?
What is specificity in CSS?
What does !important do in CSS?
What are pseudo-classes and pseudo-elements in CSS?