Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

content — CSS generated content

The content property specifies CSS-generated content, most commonly in ::before and ::after. It can add text, images, attribute values, or counters without putting them in the document markup.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

content: normal | none | [ <content-replacement> | <content-list> ] [ / <alt-text> ]?;

content specifies content for presentation. It is most commonly used with ::before and ::after. Its initial value is normal, and it is not inherited. In the example, pseudo-elements add brackets around CSS.

For ::before and ::after, both normal and none mean that no pseudo-element is generated. By contrast, content: "" creates a pseudo-element with empty content that can still be styled. On an ordinary element, a text list does not replace its text; image replacement is a separate case.

Values include strings, images, attr(), counter() counters, and quotation keywords such as open-quote. Successive list components are added in their specified order. The optional part after / provides a text alternative for accessibility. The content before / still determines what is rendered visually.

Keep essential content and labels in the document. Check accessibility in the target browser and assistive technology. The full grammar comes from an evolving specification draft, not a claim of Chromium 152 support.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>content example</title>
<style>
  .tag::before { content: "["; }
  .tag::after { content: "]"; }
</style>
<p class="tag">CSS</p>
</html>

Result

[CSS]

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources