SyntaxStudy
Sign Up
CSS Intermediate 4 min read

The content Property

The content Property

The content property is required for ::before and ::after. It can contain text strings, URLs, attribute values, counters, or be empty.

Example
/* Static text */
.version::before { content: "v"; }

/* Attribute value */
a[href]::after { content: " (" attr(href) ")"; }

/* URL (loads an image) */
.icon::before { content: url("icon.svg"); }

/* Counter */
ol li::before { content: counter(list-counter) ". "; }

/* Empty (for decorative shapes) */
.divider::after { content: ""; display: block; height: 2px; }
Pro Tip

Use attr() in content to display HTML attribute values — useful for printing link URLs beside anchor text.