The content CSS property replaces an element with a generated value. Objects inserted using the content property are anonymous replaced elements.

/* Keywords that cannot be combined with other values */
content: normal;
content: none;

/* <image> values */
content: url("");
content: linear-gradient(#e66465, #9198e5);

/* alt text for generated content, added in the Level 3 specification */
content: url("") / "This is the alt text";

/* values below can only be applied to generated content using ::before and ::after */

/* <string> value */
content: "prefix";

/* <counter> values, optionally with <list-style-type> */
content: counter(chapter_counter);
content: counter(chapter_counter, upper-roman);
content: counters(section_counter, ".");
content: counters(section_counter, ".", decimal-leading-zero);

/* attr() value linked to the HTML attribute value */
content: attr(value string);

/* Language- and position-dependent keywords */
content: open-quote;
content: close-quote;
content: no-open-quote;
content: no-close-quote;

/* Except for normal and none, several values can be used simultaneously */
content: open-quote chapter_counter;

/* Global values */
content: inherit;
content: initial;
content: unset;



The pseudo-element is not generated.
Computes to none for the ::before and ::after pseudo-elements.
<string> (en-US)
Specifies the "alt text" for the element. This value can be any number of text characters. Non-Latin characters must be encoded using their Unicode escape sequences: for example, \000A9 represents the copyright symbol.
<image> (en-US)
An <image> (en-US), denoted by the <url> (en-US) or <gradient> (en-US) data type, or part of the webpage, defined by the element() (en-US) function, denoting the content to display.
<counter> (en-US)
The value of a CSS counter, generally a number produced by computations defined by <counter-reset> (en-US) and <counter-increment> (en-US) properies. It can be displayed using either the counter (en-US) or counters (en-US) function.

The counter (en-US) function has two forms: 'counter(name)' or 'counter(name, style)'. The generated text is the value of the innermost counter of the given name in scope at the given pseudo-element. It is formatted in the specified <list-style-type> (en-US) (decimal by default).

The counters (en-US) function also has two forms: 'counters(name, string)' or 'counters(name, string, style)'. The generated text is the value of all counters with the given name in scope at the given pseudo-element, from outermost to innermost, separated by the specified string. The counters are rendered in the indicated <list-style-type> (en-US) (decimal by default).

The value of the element's attribute x as a string. If there is no attribute x, an empty string is returned. The case-sensitivity of attribute names depends on the document language.
open-quote | close-quote
These values are replaced by the appropriate string from the quotes (en-US) property.
no-open-quote | no-close-quote
Introduces no content, but increments (decrements) the level of nesting for quotes.

Accessibility concerns

CSS-generated content is not included in the DOM. Because of this, it will not be represented in the accessibility tree and certain assistive technology/browser combinations will not announce it. If the content conveys information that is critical to understanding the page's purpose, it is better to include it in the main document.

Formal definition

Initial value (en-US)normal
Applies toAll elements, tree-abiding pseudo-elements, and page margin boxes
Inherited (en-US)no
Computed value (en-US)On elements, always computes to normal. On ::before (en-US) and ::after (en-US), if normal is specified, computes to none. Otherwise, for URI values, the absolute URI; for attr() values, the resulting string; for other keywords, as specified.
Animation typediscrete

Formal syntax

normal | (en-US) none | (en-US) [ (en-US) <content-replacement> | (en-US) <content-list> ] (en-US) [ (en-US)/ <string> (en-US) ] (en-US)? (en-US)

<content-replacement> = <image> (en-US)
<content-list> = [ (en-US) <string> (en-US) | (en-US) contents | (en-US) <image> (en-US) | (en-US) <quote> | (en-US) <target> | (en-US) <leader()> ] (en-US)+ (en-US)

<image> = <url> (en-US) | (en-US) <image()> | (en-US) <image-set()> | (en-US) <element()> | (en-US) <paint()> | (en-US) <cross-fade()> | (en-US) <gradient>
<quote> = open-quote | (en-US) close-quote | (en-US) no-open-quote | (en-US) no-close-quote
<target> = <target-counter()> | (en-US) <target-counters()> | (en-US) <target-text()>
<leader()> = leader( <leader-type> )

<image()> = image( <image-tags>? (en-US) [ (en-US) <image-src>? (en-US) , <color> (en-US)? (en-US) ] (en-US)! (en-US) )
<image-set()> = image-set( <image-set-option># (en-US) )
<element()> = element( <id-selector> )
<paint()> = paint( <ident> (en-US), <declaration-value>? (en-US) )
<cross-fade()> = cross-fade( <cf-mixing-image> , <cf-final-image>? (en-US) )
<gradient> = <linear-gradient()> | (en-US) <repeating-linear-gradient()> | (en-US) <radial-gradient()> | (en-US) <repeating-radial-gradient()> | (en-US) <conic-gradient()>
<target-counter()> = target-counter( [ (en-US) <string> (en-US) | (en-US) <url> (en-US) ] (en-US) , <custom-ident> (en-US) , <counter-style>? (en-US) )
<target-counters()> = target-counters( [ (en-US) <string> (en-US) | (en-US) <url> (en-US) ] (en-US) , <custom-ident> (en-US) , <string> (en-US) , <counter-style>? (en-US) )
<target-text()> = target-text( [ (en-US) <string> (en-US) | (en-US) <url> (en-US) ] (en-US) , [ (en-US) content | (en-US) before | (en-US) after | (en-US) first-letter ] (en-US)? (en-US) )
<leader-type> = dotted | (en-US) solid | (en-US) space | (en-US) <string> (en-US)

<image-tags> = ltr | (en-US) rtl
<image-src> = <url> (en-US) | (en-US) <string> (en-US)
<color> = <rgb()> | (en-US) <rgba()> | (en-US) <hsl()> | (en-US) <hsla()> | (en-US) <hex-color> | (en-US) <named-color> (en-US) | (en-US) currentcolor | (en-US) <deprecated-system-color> (en-US)
<image-set-option> = [ (en-US) <image> (en-US) | (en-US) <string> (en-US) ] (en-US) <resolution> (en-US)
<id-selector> = <hash-token>
<cf-mixing-image> = <percentage> (en-US)? (en-US) && (en-US) <image> (en-US)
<cf-final-image> = <image> (en-US) | (en-US) <color> (en-US)
<linear-gradient()> = linear-gradient( [ (en-US) <angle> (en-US) | (en-US) to <side-or-corner> ] (en-US)? (en-US) , <color-stop-list> )
<repeating-linear-gradient()> = repeating-linear-gradient( [ (en-US) <angle> (en-US) | (en-US) to <side-or-corner> ] (en-US)? (en-US) , <color-stop-list> )
<radial-gradient()> = radial-gradient( [ (en-US) <ending-shape> || (en-US) <size> ] (en-US)? (en-US) [ (en-US) at <position> (en-US) ] (en-US)? (en-US) , <color-stop-list> )
<repeating-radial-gradient()> = repeating-radial-gradient( [ (en-US) <ending-shape> || (en-US) <size> ] (en-US)? (en-US) [ (en-US) at <position> (en-US) ] (en-US)? (en-US) , <color-stop-list> )
<conic-gradient()> = conic-gradient( [ (en-US) from <angle> (en-US) ] (en-US)? (en-US) [ (en-US) at <position> (en-US) ] (en-US)? (en-US), <angular-color-stop-list> )
<counter-style> = <counter-style-name> | (en-US) symbols()

<rgb()> = rgb( <percentage> (en-US){ (en-US)3} (en-US) [ (en-US) / <alpha-value> ] (en-US)? (en-US) ) | (en-US) rgb( <number> (en-US){ (en-US)3} (en-US) [ (en-US) / <alpha-value> ] (en-US)? (en-US) ) | (en-US) rgb( <percentage> (en-US)# (en-US){ (en-US)3} (en-US) , <alpha-value>? (en-US) ) | (en-US) rgb( <number> (en-US)# (en-US){ (en-US)3} (en-US) , <alpha-value>? (en-US) )
<rgba()> = rgba( <percentage> (en-US){ (en-US)3} (en-US) [ (en-US) / <alpha-value> ] (en-US)? (en-US) ) | (en-US) rgba( <number> (en-US){ (en-US)3} (en-US) [ (en-US) / <alpha-value> ] (en-US)? (en-US) ) | (en-US) rgba( <percentage> (en-US)# (en-US){ (en-US)3} (en-US) , <alpha-value>? (en-US) ) | (en-US) rgba( <number> (en-US)# (en-US){ (en-US)3} (en-US) , <alpha-value>? (en-US) )
<hsl()> = hsl( <hue> <percentage> (en-US) <percentage> (en-US) [ (en-US) / <alpha-value> ] (en-US)? (en-US) ) | (en-US) hsl( <hue>, <percentage> (en-US), <percentage> (en-US), <alpha-value>? (en-US) )
<hsla()> = hsla( <hue> <percentage> (en-US) <percentage> (en-US) [ (en-US) / <alpha-value> ] (en-US)? (en-US) ) | (en-US) hsla( <hue>, <percentage> (en-US), <percentage> (en-US), <alpha-value>? (en-US) )
<side-or-corner> = [ (en-US) left | (en-US) right ] (en-US) || (en-US) [ (en-US) top | (en-US) bottom ] (en-US)
<color-stop-list> = [ (en-US) <linear-color-stop> [ (en-US), <linear-color-hint>] (en-US)? (en-US) ] (en-US)# (en-US) , <linear-color-stop>
<ending-shape> = circle | (en-US) ellipse
<size> = closest-side | (en-US) farthest-side | (en-US) closest-corner | (en-US) farthest-corner | (en-US) <length> | (en-US) <length-percentage>{ (en-US)2} (en-US)
<position> = [ (en-US) [ (en-US) left | (en-US) center | (en-US) right ] (en-US) || (en-US) [ (en-US) top | (en-US) center | (en-US) bottom ] (en-US) | (en-US) [ (en-US) left | (en-US) center | (en-US) right | (en-US) <length-percentage> ] (en-US) [ (en-US) top | (en-US) center | (en-US) bottom | (en-US) <length-percentage> ] (en-US)? (en-US) | (en-US) [ (en-US) [ (en-US) left | (en-US) right ] (en-US) <length-percentage> ] (en-US) && (en-US) [ (en-US) [ (en-US) top | (en-US) bottom ] (en-US) <length-percentage> ] (en-US) ] (en-US)
<angular-color-stop-list> = [ (en-US) <angular-color-stop> [ (en-US), <angular-color-hint>] (en-US)? (en-US) ] (en-US)# (en-US) , <angular-color-stop>
<counter-style-name> = <custom-ident> (en-US)

<alpha-value> = <number> (en-US) | (en-US) <percentage> (en-US)
<hue> = <number> (en-US) | (en-US) <angle> (en-US)
<linear-color-stop> = <color> (en-US) <color-stop-length>? (en-US)
<linear-color-hint> = <length-percentage>
<length-percentage> = <length> | (en-US) <percentage> (en-US)
<angular-color-stop> = <color> (en-US) && (en-US) <color-stop-angle>? (en-US)
<angular-color-hint> = <angle-percentage>

<color-stop-length> = <length-percentage>{ (en-US)1,2} (en-US)
<color-stop-angle> = <angle-percentage>{ (en-US)1,2} (en-US)
<angle-percentage> = <angle> (en-US) | (en-US) <percentage> (en-US)


Headings and quotes

This example inserts quotation marks around quotes, and adds the word "Chapter" before headings.


<p>According to Sir Tim Berners-Lee,
  <q cite="">I was
    lucky enough to invent the Web at the time when the Internet
    already existed - and had for a decade and a half.</q>
  We must understand that there is nothing fundamentally wrong
  with building on the contributions of others.

<p>According to the Mozilla Manifesto,
  <q cite="">Individuals
    must have the ability to shape the Internet and
    their own experiences on the Internet.</q>
  Therefore, we can infer that contributing to the open web
  can protect our own individual experiences on it.


q {
  color: blue;

q::before {
  content: open-quote;

q::after {
  content: close-quote;

h1::before  {
  content: "Chapter ";  /* The trailing space creates separation
                           between the added content and the
                           rest of the content */


Image combined with text

This example inserts an image before the link. If the image is not found, it inserts text instead.


<a href="">Mozilla Home Page</a>


a::before {
  content: url("") / " MOZILLA: ";
  font: x-small Arial, sans-serif;
  color: gray;


Targeting classes

This example inserts additional text after special items in a list.


<h2>Paperback Best Sellers</h2>
  <li>Political Thriller</li>
  <li class="new-entry">Halloween Stories</li>
  <li>My Biography</li>
  <li class="new-entry">Vampire Romance</li>


.new-entry::after {
  content: " New!";  /* The leading space creates separation
                        between the added content and the
                        rest of the content */
  color: red;


Images and element attributes

This example inserts an image before each link, and adds its id attribute after.


  <li><a id="moz" href="">
    Mozilla Home Page</a></li>
  <li><a id="mdn" href="">
    Mozilla Developer Network</a></li>


a {
  text-decoration: none;
  border-bottom: 3px dotted navy;

a::after {
  content: " (" attr(id) ")";

#moz::before {
  content: url("");

#mdn::before {
  content: url("");

li {
  margin: 1em;


Element replacement

This example replaces an element's content with an image. You can replace the contents of an element with either a <url> (en-US) or an <image> (en-US) value. Content added with ::before or ::after will not be generated as the contents of the element have been replaced.


<div id="replaced">Mozilla</div>


#replaced {
  content: url("");

#replaced::after { /* will not show if element replacement is supported */
  content: " (" attr(id) ")";



Specification Status Comment
CSS Generated Content Module Level 3
The definition of 'content' in that specification.
Working Draft Adds support for alt-text
CSS Level 2 (Revision 1)
The definition of 'content' in that specification.
Recommendation Initial definition

Browser compatibility

BCD tables only load in the browser

See also