content

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("http://www.example.com/test.png");
content: linear-gradient(#e66465, #9198e5);
content: image-set("image1x.png" 1x, "image2x.png" 2x);

/* alt text for generated content, added in the Level 3 specification */
content: url("http://www.example.com/test.png") / "This is the alt text";

/* <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 counter(chapter_counter);

/* Global values */
content: inherit;
content: initial;
content: revert;
content: revert-layer;
content: unset;


Syntax
Values
 none  When applied to a pseudo-element, the pseudo-element is not generated. If applied to an element, the value has no effect.  normal  Computes to none for the 8b7c:f320:99b9:690f:4595:cd17:293a:c069ore and 8b7c:f320:99b9:690f:4595:cd17:293a:c069ter pseudo-elements.  <string>  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>  An <image>, denoted by the url() or <gradient> data type, or part of the webpage, defined by the element() function, denoting the content to display.  counter()  The value of a CSS counter, generally a number produced by computations defined by <counter-reset> and <counter-increment> properties. It can be displayed using either the counter() or counters() function. The counter() 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> (decimal by default). The counters() 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> (decimal by default).  attr(x)  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 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.  Accessibility support for CSS generated content – Tink Explanation of WCAG, Guideline 1.3 – MDN Understanding Success Criterion 1.3.1 | W3C Understanding WCAG 2.0 
Formal definition


Initial value
normal


Applies to
All elements, tree-abiding pseudo-elements, and page margin boxes


Inherited
no


Computed value
On elements, always computes to normal. On 8b7c:f320:99b9:690f:4595:cd17:293a:c069ore and 8b7c:f320:99b9:690f:4595:cd17:293a:c069ter, 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 type
discrete

Formal syntax
content =   normal                                              |  none                                                |  [ <content-replacement> | <content-list> ] [ / [ <string> | <counter> ]+ ]?  |  element( )                                          <content-replacement> =   <image>  <content-list> =   [ <string> | contents | <image> | <counter> | <quote> | <target> | <leader()> ]+  <counter> =   <counter()>   |  <counters()>  <image> =   <url>       |  <gradient>  <quote> =   open-quote      |  close-quote     |  no-open-quote   |  no-close-quote  <target> =   <target-counter()>   |  <target-counters()>  |  <target-text()>      <leader()> =   leader( <leader-type> )  <counter()> =   counter( <counter-name> , <counter-style>? )  <counters()> =   counters( <counter-name> , <string> , <counter-style>? )  <target-counter()> =   target-counter( [ <string> | <url> ] , <custom-ident> , <counter-style>? )  <target-counters()> =   target-counters( [ <string> | <url> ] , <custom-ident> , <string> , <counter-style>? )  <target-text()> =   target-text( [ <string> | <url> ] , [ content | before | after | first-letter ]? )  <leader-type> =   dotted    |  solid     |  space     |  <string>  <counter-style> =   <counter-style-name>  |  <symbols()>           <symbols()> =   symbols( <symbols-type>? [ <string> | <image> ]+ )  <symbols-type> =   cyclic      |  numeric     |  alphabetic  |  symbolic    |  fixed       Examples
Headings and quotes

This example inserts quotation marks around quotes, and adds the word "Chapter" before headings. HTML <h1>5</h1>
<p>According to Sir Tim Berners-Lee,
  <q cite="http://www.w3.org/People/Berners-Lee/FAQ.html#Internet">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>

<h1>6</h1>
<p>According to the Mozilla Manifesto,
  <q cite="http://www.mozilla.org/en-US/about/manifesto/">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.
</p>
 CSS q {
  color: blue;
}

q8b7c:f320:99b9:690f:4595:cd17:293a:c069ore {
  content: open-quote;
}

q8b7c:f320:99b9:690f:4595:cd17:293a:c069ter {
  content: close-quote;
}

h8b7c:f320:99b9:690f:4595:cd17:293a:c069before {
  content: "Chapter ";  /* The trailing space creates separation
                           between the added content and the
                           rest of the content */
}
 Result

Image combined with text

This example inserts an image before the link. If the image is not found, it inserts text instead. HTML <a href="https://www.mozilla.org/en-US/">Mozilla Home Page</a>
 CSS 8b7c:f320:99b9:690f:4595:cd17:293a:c069before {
  content: url("https://mozorg.cdn.mozilla.net/media/img/favicon.ico") / " MOZILLA: ";
  font: x-small Arial, sans-serif;
  color: gray;
}
 Result

Targeting classes

This example inserts additional text after special items in a list. HTML <h2>Paperback Best Sellers</h2>
<ol>
  <li>Political Thriller</li>
  <li class="new-entry">Halloween Stories</li>
  <li>My Biography</li>
  <li class="new-entry">Vampire Romance</li>
</ol>
 CSS .new-entry8b7c:f320:99b9:690f:4595:cd17:293a:c069ter {
  content: " New!";  /* The leading space creates separation
                        between the added content and the
                        rest of the content */
  color: red;
}
 Result

Images and element attributes

This example inserts an image before each link, and adds its id attribute after. HTML <ul>
  <li><a id="moz" href="https://www.mozilla.org/">
    Mozilla Home Page</a></li>
  <li><a id="mdn" href="https://developer.mozilla.org/">
    Mozilla Developer Network</a></li>
</ul>
 CSS a {
  text-decoration: none;
  border-bottom: 3px dotted navy;
}

8b7c:f320:99b9:690f:4595:cd17:293a:c069after {
  content: " (" attr(id) ")";
}

#moz8b7c:f320:99b9:690f:4595:cd17:293a:c069ore {
  content: url("https://mozorg.cdn.mozilla.net/media/img/favicon.ico");
}

#mdn8b7c:f320:99b9:690f:4595:cd17:293a:c069ore {
  content: url("mdn-favicon16.png");
}

li {
  margin: 1em;
}
 Result

Element replacement

This example replaces an element's content with an image. You can replace the contents of an element with either a url() or an <image> value. Content added with 8b7c:f320:99b9:690f:4595:cd17:293a:c069ore or 8b7c:f320:99b9:690f:4595:cd17:293a:c069ter will not be generated as the contents of the element have been replaced. HTML <div id="replaced">Mozilla</div>
 CSS #replaced {
  content: url("mdn.svg");
}

#repl8b7c:f320:99b9:690f:4595:cd17:293a:c069after { /* will not show if element replacement is supported */
  content: " (" attr(id) ")";
}
 Result

Specifications

Specification
CSS Generated Content Module Level 3 # content-property

Browser compatibility




Desktop
Mobile



Chrome
Edge
Firefox
Internet Explorer
Opera
Safari
WebView Android
Chrome Android
Firefox for Android
Opera Android
Safari on IOS
Samsung Internet




content
1
12
1
8
4
1
4.4
18
4
10.1
1
1.0


alt_text
77
79
No
No
64
No
77
77
No
55
No
12.0


element_replacement
28
79
63
No
7
9
4.4
28
63
10.1
9
1.5


none_applies_to_elements
No
No
91
No
No
No
No
No
No
No
No
No


url
1
12
1
8
7
1
37
18
4
14
1
1.0



See also
 Replaced elements 8b7c:f320:99b9:690f:4595:cd17:293a:c069ter 8b7c:f320:99b9:690f:4595:cd17:293a:c069ore 8b7c:f320:99b9:690f:4595:cd17:293a:c069marker contain quotes 
url() function 

Found a problem with this page?

Edit on GitHub
Source on GitHub
Report a problem with this content on GitHub
Want to fix the problem yourself? See our Contribution guide.


Last modified: Aug 23, 2022, by MDN contributors


    
{'path': 'public/docs/css/content.html', 'source': 'DevDocs.IO'}