πŸ’‘ This page contain affiliate links. By making a purchase through them, we may earn a commission at no extra cost to you.
What is the Difference Between Single and Double Colon in CSS?

What is the Difference Between Single and Double Colon in CSS?

Ferenc Almasi β€’ Last updated 2020 November 04 β€’ Read time 2 min read
  • twitter
  • facebook
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  { ... }
double-vs-single.css

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-classes.css

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 */
}
pseudo-elements.css
What is the difference between sing and double colon in CSS?
If you would like to see more Webtips, follow @flowforfrank

10 Best Practices for Quickly Improving Your CSS
Looking to improve your skills? Master CSS from start to finish.
Master CSSinfo Remove ads

Resources:

  • twitter
  • facebook
CSS
Did you find this page helpful?
πŸ“š More Webtips
Frontend Course Dashboard
Master the Art of Frontend
  • check Access 100+ interactive lessons
  • check Unlimited access to hundreds of tutorials
  • check Prepare for technical interviews
Become a Pro

Courses

Recommended

This site uses cookies We use cookies to understand visitors and create a better experience for you. By clicking on "Accept", you accept its use. To find out more, please see our privacy policy.