148

What does the double colon (::) mean in CSS?

For example:

input[type=text]::-ms-clear { display: none; }
Salman A
  • 262,204
  • 82
  • 430
  • 521
Dilhan Jayathilake
  • 1,860
  • 2
  • 17
  • 15

3 Answers3

140

It means pseudo element selector. It means the element to the right doesn't exist in the normal DOM, but can be selected.

A pseudo-element is made of two colons (::) followed by the name of the pseudo-element.

Source

It was originally only a single colon, but was changed to differentiate it from pseudo classes (like :hover, :first-child, :not etc). It's best to use : for before and after pseudo elements since the single colon has better browser support, namely in earlier IE versions.

Salman A
  • 262,204
  • 82
  • 430
  • 521
alex
  • 479,566
  • 201
  • 878
  • 984
33

The :: operator indicates you are selecting a pseudo element, one which does not actually exist as an element but can still be targeted for styling.

Example of this include several vendor-specific implementations such as the -ms-clear sample you provide, most browsers also have pseudo elements to style scroll bars and other native UI elements, but there are also a lot of predefined pseudo elements which can be referenced for practical reasons, such as first-line and first-letter.

The :before and :after pseudo elements even allow you to insert actual content into the page using CSS with the content rule.

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
14

CSS3 changes the way pseudo-elements are selected, as the W3C wanted to distinguish pseudo-classes like a:visited from pseudo-elements like p::first-line. See Advanced CSS Selectors.

Eric Jablow
  • 7,874
  • 2
  • 22
  • 29