Pseudo-element

A CSS pseudo-element styles a specific part of an element, written with two colons, like ::before or ::first-line. It can also insert generated content that isn't in the HTML.

Web

The most-used pseudo-elements are ::before and ::after, which let you add decorative content (icons, quotes, shapes) via CSS without cluttering your HTML.

Others include ::first-letter and ::first-line for typographic effects, and ::placeholder for styling input placeholder text.

Examples

CSS

.quote::before {
  content: "\201C";
  font-size: 2em;
}

Output:

Adds a large opening quotation mark before each element with class 'quote'.

Learn it in a lesson

See also

Back to the Dictionary