00 Votes

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

Question by WebHorn | 2014-09-09 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?

ReplyPositiveNegative
0Best Answer0 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 ":".
2014-09-10 at 15:31

ReplyPositive Negative
Reply

Related Topics

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.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.