The content property inserts generated content into ::before and ::after pseudo-elements — no extra HTML required.
01
Generated Content
CSS-inserted text.
02
::before / ::after
Required context.
03
Default normal
No content shown.
04
Text & URLs
Strings and images.
05
attr()
From HTML attrs.
06
Decorative
Presentational use.
Fundamentals
Definition and Usage
The content CSS property is used with the ::before and ::after pseudo-elements to insert generated content into an element. It is particularly useful for adding decorative content or presentational annotations without altering the HTML markup.
Common uses include labels like “Note:”, icons before list items, external-link arrows after anchors, quote marks, and counter numbers. Remember: essential information should stay in HTML for accessibility; use content for decoration and enhancement.
💡
Beginner Tip
A pseudo-element only appears when content is set to something other than normal or none. Empty string content: ""; creates an invisible box you can style as a shape or icon background.
Foundation
📝 Syntax
The syntax for content is flexible — it can include text, images, counters, and attribute values:
::after inserts content after the link text — a common pattern for indicating links that open in a new tab.
🧠 How content Works
1
Target a pseudo-element
Write a rule for ::before or ::after on a selector.
Prerequisite
2
You set content
Provide a string, url(), attr(), or keyword value.
CSS rule
3
Browser generates a box
The pseudo-element appears inline with the element, styled by your other CSS rules.
Rendering
=
✨
Decorative enhancement
Extra visual content appears without changing your HTML structure.
Compatibility
Modern Browser Support
The content property is widely supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera.
✓ Baseline · Modern browsers
Generated content everywhere
All major browsers support content on pseudo-elements, including older versions of these browsers.
99%Modern browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll modern versions
Full support
content property99% supported
Bottom line: Use content reliably on pseudo-elements. Keep critical text in HTML for accessibility.
Wrap Up
Conclusion
The content property in CSS is a versatile tool for inserting generated content without altering the HTML structure. It can be particularly useful for adding decorative elements, annotations, or other presentational content.
By understanding and utilizing the content property, you can enhance the visual appeal and functionality of your web projects.
Use content for decorative labels, icons, and indicators
Pair with ::before and ::after pseudo-elements
Use attr() for data-driven presentational hints
Keep essential information in HTML for screen readers
Use content: ""; to create styled shape boxes
❌ Don’t
Put critical content only in CSS generated text
Apply content directly to regular elements — it has no effect
Rely on generated content for SEO-important text
Forget quotes around text strings
Overuse decorative prefixes that clutter the UI
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about content
Use these points when inserting generated content.
5
Core concepts
✨01
Generated
CSS-inserted.
Purpose
⚙02
Default normal
No content.
Default
🖌03
::before/::after
Required context.
Syntax
📝04
Many values
Text, url, attr.
Values
♿05
Decorative
Not essential text.
A11y
❓ Frequently Asked Questions
content inserts generated content into ::before and ::after pseudo-elements. It lets you add decorative or presentational text and icons without changing HTML markup.
The initial value is normal, which means no content is generated for the pseudo-element.
No. content only applies to ::before, ::after, and ::marker pseudo-elements (and similar generated-content contexts). Setting content on a div has no effect.
HTML text is part of the document and accessible to screen readers by default. Generated content from CSS is presentational — use it for decoration, not essential information.
Write content: attr(data-label) or content: attr(href) to pull a value from an HTML attribute into the pseudo-element, such as showing a link URL on hover.