Skip to main content
D
CSS
CSS Pseudo-Elements

CSS Pseudo-Elements

CSS pseudo-elements style specific parts of an element.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

CSS pseudo-elements target sub-sections of an HTML element without needing extra tags. Developers use them to style just the first letter of a paragraph or inject decorative icons before a heading. They use a double colon syntax.

Syntax

Syntax
1/* pseudo-element syntax */
2selector::pseudo-element {
3  property: value;
4}

Example

Example
1/* this styles the first line */
2p::first-line {
3  font-weight: bold;
4  color: red;
5}

Key Points

  • Pseudo-elements target partial element contents.
  • The `::first-letter` creates drop caps.
  • The `::before` injects visual content before the element.
  • The `::after` injects visual content after the element.

Up Next

Continue your journey with the next topic.

Go to CSS Opacity