CSS content Property Explained

What the CSS content property does, with an example.

Published November 7, 2026

content inserts generated content in ::before and ::after pseudo-elements, such as text, quotes, counters or images. It is required for pseudo-elements to render.

How it works

Use content: '' for purely decorative shapes. attr(data-label) can insert attribute values.

Generated content is not selectable and may not be read reliably by screen readers, so don't put essential information there.

Values and effects

content: ''; → empty box (decoration)
content: '→'; → text
content: attr(data-tip); → attribute text
content: counter(item); → counter value

Practical examples

Decorative line

.title::after { content: ''; display: block; width: 40px; height: 3px; background: #2f81f7; }

Tooltip text

[data-tip]::after { content: attr(data-tip); }

External link icon

a[href^='http']::after { content: ' ↗'; }

Common mistakes

  • Forgetting content so nothing appears.
  • Putting important text in pseudo-elements.
  • Using content outside ::before/::after (limited use).

Key takeaways

  • content in one line: content inserts generated content in ::before and ::after pseudo-elements, such as text, quotes, counters or images.
  • Inspect it live in DevTools → Styles.
  • Test across browsers and screen sizes.

FAQ

Why doesn't ::before show?

It needs a content property, even an empty string.

Is content supported in all browsers?

Yes in all modern browsers; check caniuse.com for edge cases.

More CSS articles