CSS Pseudo-elements

A CSS pseudo-element is used to style specified parts of an element.

For example, it can be used to:

  • Style the first letter, or line, of an element

  • Insert content before, or after, the content of an element

Syntax:

selector::pseudo-element {
  property: value;
}

All CSS Pseudo Elements

Selector
Example
Example description

p::after

Insert something after the content of each <p> element

div.redDiv::before

Insert something before the content of each <div class='redDiv'> element

.someClass::first-letter

Selects the first letter of each element haing classsomeClass

p::first-line

Selects the first line of each <p> element

::marker

Selects the markers of list items

p::selection

Selects the portion of an element that is selected by a user

Last updated