Open Playground
CSS ReferencesLesson #212

CSS Pseudo-elements

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

A CSS pseudo-element is used to style specific 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 an element
  • Style the markers of list items
  • Style the viewbox behind a dialog box

The table below shows the different pseudo-elements in CSS:

Pseudo-elementExampleExample description
::afterp::after div::afterInserts something after the content of the specified element
::backdropdialog::backdropStyles the viewbox behind a dialog box or popover element
::beforep::before div::beforeInserts something before the content of the specified element
::file-selector-button::file-selector-buttonSelects any button of type <input type="file">
::first-letterp::first-letterSelects the first letter of every <p> element
::first-linep::first-lineSelects the first line of every <p> element
::grammar-error::grammar-errorStyles a text that the browser has flagged as grammatically incorrect
::highlight()::highlight(custom-name)Selects a custom highlight
::marker::markerSelects the markers of list items
::placeholderinput::placeholder textarea::placeholderStyles the placeholder text of <input> or <textarea> elements
::selection::selectionStyles the user-selected text
::spelling-error::spelling-errorStyles a text that the browser has flagged as incorrectly spelled
::view-transition::view-transitionRepresents the root of the view transitions overlay, which contains all view transition on the page
::view-transition-group::view-transition-groupRepresents a single view transition snapshot group
::view-transition-image-pair::view-transition-image-pairRepresents a container for a view transition's "old" and "new" view states - before and after the transition
::view-transition-new::view-transition-newRepresents the "new" view state of a view transition
::view-transition-old::view-transition-oldRepresents the "old" view state of a view transition