CSS Portal

CSS content Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The content property is the mechanism used by CSS to create generated content that does not exist in the source DOM. It is most commonly used in conjunction with pseudo-elements (for example ::before and ::after) to inject extra textual or graphical material at render time. Because the content is created by the style layer rather than by the document tree, it behaves like presentation-only content: it can visually augment a page without changing the underlying HTML structure.

Although generated via CSS, the boxes that carry generated content participate in normal layout and can be controlled by other CSS rules applied to the pseudo-element. Their display and placement are subject to the same layout rules as regular elements, and you can influence sizing, flow, and stacking through the pseudo-element’s own properties — for example display controls the box type the generated content produces. The generated content can also be used together with counter mechanisms to render automatic numbering; these counters are managed by counter-related properties such as counter-reset and the corresponding incrementing properties.

Because generated content is not part of the document’s DOM, it has important accessibility and interactivity implications. Assistive technologies and scripting environments treat it differently across user agents: some screen readers may ignore it, and it cannot be targeted by document-level selection or form submission in the same way as real DOM text. Consequently, content that is essential for understanding or interacting with a page should live in the HTML itself rather than be supplied only via content.

Finally, generated content can be styled, transformed and animated like any other layer of presentation, which makes it useful for decorative effects, status indicators, and small UI affordances without extra markup. When using animations or transitions on the pseudo-element carrying generated content, you are combining that presentational layer with the page’s visual dynamics — for instance, effects driven by the element’s animation rules such as animation. Keep in mind the trade-off between convenience and semantics: for maintainable, accessible interfaces, reserve generated content for nonessential enhancements.

Definition

Initial value
normal
Applies to
::before and ::after pseudo-elements
Inherited
No
Computed value
Specified value
Animatable
No
JavaScript syntax
object.style.content

Interactive Demo

Example of content property

Syntax

content: [ <uri> ',' ]* [ normal | none | inhibit | <content-list> ]

Values

  • <string>
  • <uri>
  • <counter>
  • open-quote
  • close-quote
  • no-open-quote
  • no-close-quote
  • attr
  • inherit

Example

<body>
<section class="examples">
<h2 class="decorated" data-emoji="🔥">Decorated Heading</h2>
<p class="note" data-source="example.com">This paragraph shows an attribute-based generated note</p>
<a class="external" href="https://example.com">External link</a>

<ol class="counter-list">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>

<blockquote class="quote">
Creativity is intelligence having fun.
<cite> - Albert Einstein</cite>
</blockquote>
</section>
</body>
/* Example CSS demonstrating the content property */
.examples {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, "Helvetica Neue", Arial;
  color: #222;
  max-width: 700px;
  margin: 40px auto;
  line-height: 1.5;
}

.decorated {
  position: relative;
  font-size: 1.5rem;
}
.decorated::before {
  /* Insert emoji from the data-emoji attribute before the heading */
  content: attr(data-emoji) " ";
  margin-right: 0.35rem;
}

.note::after {
  /* Append a small source note using attr() */
  content: " (source: " attr(data-source) ")";
  color: #6b7280;
  font-size: 0.9em;
}

.external::after {
  /* Add a visual indicator for external links */
  content: "↗";
  margin-left: 0.25rem;
  color: #1f6feb;
}

.counter-list {
  counter-reset: item;
  padding-left: 0;
  margin-top: 1rem;
}
.counter-list li {
  counter-increment: item;
  position: relative;
  padding-left: 2rem;
  margin-bottom: 0.5rem;
}
.counter-list li::before {
  /* Use a counter to generate list numbers */
  content: counter(item) ".";
  position: absolute;
  left: 0;
  color: #1f6feb;
  font-weight: 600;
}

.quote {
  margin-top: 1.5rem;
  padding-left: 1rem;
  border-left: 4px solid #e5e7eb;
  color: #374151;
  quotes: "“" "”" "‘" "’"; /* define quote characters */
}
.quote::before {
  /* Use open-quote to insert the opening quotation mark */
  content: open-quote;
  font-size: 2rem;
  line-height: 0;
  margin-right: 0.25rem;
  vertical-align: -0.3rem;
  color: #9ca3af;
}
.quote::after {
  /* Use close-quote to insert the closing quotation mark */
  content: close-quote;
}

cite {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: #6b7280;
}

Browser Support

The following information will show you the current browser support for the CSS content property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!