CSSEasy
What is the difference between a pseudo-class and a pseudo-element?
By FrontendPro Editorial Team Updated 8/7/2026
#css#selectors
Answer
- A pseudo-class (
:hover,:focus-visible,:nth-child,:has) matches an element in a given state. - A pseudo-element (
::before,::after,::marker,::placeholder,::selection) creates or targets a virtual sub-part of an element.
css
a:hover { text-decoration: underline; }
.card::after { content: ""; position: absolute; inset: 0; }
::before/::after need a content value to render at all, and don't work on replaced elements (img, input).
