what i don't understand about these concepts is when should i use a pseudo-class selector like :before
or :first-child
and when to use a pseudo-element selector like ::before
.
Asked
Active
Viewed 348 times
-1

Amir2170
- 1
- 2
-
Note: CSS3 introduced the ::before notation (with two colons) to distinguish pseudo-classes from pseudo-elements. Browsers also accept :before, introduced in CSS2. - https://developer.mozilla.org/en-US/docs/Web/CSS/::before#syntax – A. Meshu Nov 02 '21 at 11:50
2 Answers
1
The single colon syntax is an older implementation. In general, there are pseudo-elements ::
& pseudo-classes :
, and they are not identical. In this case though, browsers still support the outdated single-colon syntax.
This means that in your example with :before
/::before
, it will not make a difference to the outcome, but in general you should use the double colon syntax, because before & after are pseudo-elements, not pseudo-classes.
Read more on MDN.

Nachtfunke
- 329
- 1
- 14