What is the use of Pseudo Element in CSS?

A CSS pseudo-element is used to style specified parts of an element. In CSS, Pseudo-elements selector selects specific part of an HTML element.

  • The after pseudo-element can be used to insert some content after the content of an element.
  • The before pseudo-element can be used to insert some content before the content of an element.
  • The first-letter pseudo-element can only be applied to block-level elements.

The following properties apply to the first-letter pseudo- element:

  • font properties
  • color properties
  • background properties
  • margin properties
  • padding properties
  • border properties
  • text-decoration
  • vertical-align (only if “float” is “none”)
  • text-transform
  • line-height
  • float
  • clear

The first-line pseudo-element is used to add a special style to the first line of a text.

The selection pseudo-element matches the portion of an element that is selected by a user.