
What is the Difference Between Single and Double Colon in CSS?
Do you know what is the difference between single and double colon in CSS? Or did you know that there is a difference at all?
Copied to clipboard! Playground
/* CSS3 syntax */
.css3::before { ... },
.css3::after { ... }
/* CSS2 syntax */
.css2:before { ... },
.css2:after { ... }
Single is used for pseudo-classes like :active
or :hover
, while double is used for pseudo-elements like ::before
or ::after
. So what is the difference between pseudo-classes and pseudo-elements?
Pseudo-classes
Pseudo-classes as used for selecting states of an element. They are not elements themselves. Some examples are:
Copied to clipboard! Playground
.anchor:hover {
/* styles for the hover state of the anchor */
}
.anchor:visited {
/* styles for already visited anchor */
}
Pseudo-elements
pseudo-elements on the other hand are used for selecting parts of an actual DOM element, such as what comes before or after it, specific letters, or even lines. Some examples are:
Copied to clipboard! Playground
.paragraph::before {
/* style the pseudo element before the paragraph */
}
.paragraph::after {
/* style the pseudo element after the paragraph */
}
.paragraph::first-line {
/* style the first line of the paragraph */
}
.paragraph::first-letter {
/* style the first letter of the paragraph */
}


Looking to improve your skills? Master CSS from start to finish.

Resources:
π More Webtips
Master the Art of Frontend
Access exclusive interactive lessons
Unlimited access to hundreds of tutorials
Remove ads to learn without distractions
Courses

CSS - The Complete Guide (including Flexbox, Grid and Sass)
Including Flexbox, Grid, and Sass
Whether you're learning CSS for the first time or brushing up on your CSS skills and diving even deeper, this course is for you. Every web developer has to know CSS.

The HTML & CSS Bootcamp
From Zero to Expert!
This course covers flexbox, CSS grid, animations, responsive design, and much more! You will find tons of exercises & projects inside this course.

The Creative HTML5 & CSS3 Course
Build Awesome Websites
Learn HTML5 and CSS3 by creating three amazing, well-designed and animated websites from scratch.