CSS content Property
The content property in CSS is used to insert generated content before or after an element. It is mainly used with the ::before and ::after pseudo-elements.
1. Syntax
| Value | Description |
|---|---|
"" (empty string) | Inserts an empty content. |
"text" | Inserts specified text. |
url("image.png") | Inserts an image. |
attr(attribute-name) | Inserts an attribute value. |
counter(name) | Inserts a counter. |
none | Removes content. |
2. Example – Adding Text Before an Element
✅ Displays: š„ Hot News
3. Example – Adding Icons After a Link
✅ Displays: Read More š
4. Example – Displaying an Image Using content
✅ Inserts an image before the <div> content.
5. Example – Using attr() to Display Attributes
✅ Displays: Visit (https://example.com)
6. Example – Using counter() for Auto Numbering
✅ Auto-numbers sections dynamically.
7. Best Practices
✔ Use ::before & ::after for decorative content (icons, labels, effects).
✔ Avoid using content for essential content (not accessible by screen readers).
✔ Combine with counter-increment for auto-numbering.

