Utilizor
Contact Us

CSS Pseudo-elements

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

CSS Pseudo-elements

A 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

Example 1: Syntax

The syntax of pseudo-elements:

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

Example 2: ::first-line Pseudo-element

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

You can use the ::first-line pseudo-element to add a special effect to the first line of a text. Some more text. And more, and more, and more, and more, and more, and more, and more, and more, and more, and more, and more, and more.

Example 3: ::first-letter Pseudo-element

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

You can use the ::first-letter pseudo-element to add a special effect to the first letter of a text.

Example 4: ::before Pseudo-element

The ::before pseudo-element can be used to insert some content before the content of an element.

This is a heading

This is a paragraph.

Example 5: ::after Pseudo-element

The ::after pseudo-element can be used to insert some content after the content of an element.

This is a heading

This is a paragraph.

Example 6: ::selection Pseudo-element

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

Select some text in this paragraph to see the effect.

Example

p::first-line {
  color: #ff0000;
  font-variant: small-caps;
}

p::first-letter {
  color: #ff0000;
  font-size: xx-large;
}

h1::before {
  content: url(smiley.gif);
}