What does the "::before" pseudo-element do in CSS?

QuestionsQuestions8 SkillsProCustom Radio ButtonOct, 25 2025
0126

The ::before pseudo-element in CSS allows you to insert content before the content of a selected element. It is commonly used to add decorative elements or additional content without modifying the HTML structure.

Here's the basic syntax:

selector::before {
  /* CSS properties */
}

You can use the content property to specify what to insert. For example, to add a decorative icon before a paragraph:

p::before {
  content: "★"; /* Adds a star before the paragraph */
  color: gold;  /* Sets the color of the star */
}

This will display a star before the text of every <p> element on the page.

0 Comments

no data
Be the first to share your comment!