0 0 Votes

CSS: Should I use :before or ::before?

Question by WebHorn | 09/09/2014 at 23:27

Currently, I am trying to implement the pseudo-elements :before and :after in my webdesign, because I would like to insert some content with these selectors.

However, on different Internet pages, I have discovered divergent writings. Some designers are writing :before and :after with only one colon at the beginning, others are using a variant with two colons, they are writing ::before and ::after instead.

Which writing is correct and what should I use in my own CSS-Stylesheet for my website?



Show Profile | Message
0Best Answer
0 Votes

CSS3 separates between pseudo-classes (:hover, :visited, :first-child, :nth-child etc) and pseudo-elements (::before, ::after, ::first-line etc). 

This division is made visible with one or two colons in front of the notation. According to this specification, it would be more correct to choose the variant with two colons for "before" and "after".

In practice, many web designers are still using the old syntax with only one colon. The reason: Every browser supporting "::" is also supporting ":", but Internet Explorer 8 is only supporting the variation with one colon.

If you do not want to care about old browsers, you can calmed use "::", otherwise, you can always use ":".
10/09/2014 at 15:31

ReplyPositive Negative

Related Topics

CSS: span with a fixed width
Question | 1 Answer
CSS: Round Corners
Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own articles on askingbox.com. How to do.