CSS

🎯 CSS content Property

The content property in CSS is used to insert generated content into a page, usually with ::before and ::after pseudo-elements.

It allows you to add text, icons, images, counters, or attribute values without modifying the HTML structure.

💬 What is the content property?

The content property lets you insert virtual elements into the DOM visually using CSS only.

These elements are not part of the HTML code but appear in the browser.

🔹 Basic Usage

CSS

p::before {
  content: "📘 Note: ";
}
                

➡️ Adds “📘 Note:” before every paragraph without changing HTML.

🔸 Common Use Cases

  • Adding icons before text
  • Adding quotes automatically
  • Creating counters and numbered lists
  • Displaying attribute values dynamically

🧩 Values and Examples

Value Description
none No content is displayed
string Adds text or emoji content
url Adds image or icon via URL
attr() Displays HTML attribute value
counter() Creates automatic numbering
initial Resets to default value

🧩 Examples

String Example:

CSS

h1::after {
  content: " 🔥";
}
                

➡️ Adds emoji after headings.

Attribute Example:

CSS

a::after {
  content: " (" attr(href) ")";
}
                

➡️ Shows link URL next to anchor text.

Counter Example:

CSS

li::before {
  counter-increment: count;
  content: counter(count) ". ";
}
                

➡️ Automatically numbers list items.

💡 Summary

  • 🧠 In Short

  • The content property is used to insert dynamic content using CSS.
  • It works with ::before and ::after pseudo-elements.
  • It allows adding text, icons, counters, and attribute values without editing HTML.