content property CSS Reference

Definition and Usage

The content CSS property is used with the ::before and ::after pseudo-elements to generate content in an element. Objects inserted using the content property are anonymous replaced elements.

  • Initial normal
  • Applies to ::before and ::after pseudo-element
  • Inherited no
  • Media all
  • Computed Value On elements, always computes to normal. On ::before and ::after, 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.
  • Animatable no
  • Canonical order the unique non-ambiguous order defined by the formal grammar


Formal syntax: normal | none | [ <string> | <uri> | <counter> | attr() | open-quote | close-quote | no-open-quote | no-close-quote ]+
content: normal                                /* Keywords that cannot be combined with other values */
content: none
content: 'prefix'                              /* <string> value, non-latin characters must be encoded e.g. \00A0 for &nbsp; */
content: url( /* <uri> value */
content: chapter_counter                       /* <counter> values */
content: attr(value string)                    /* attr() value linked to the HTML attribute value */
content: open-quote                            /* Language- and position-dependant keywords */
content: close-quote
content: no-open-quote
content: no-close-quote
content: open-quote chapter_counter            /* Except for normal and none, several values can be used simultaneously */
content: inherit


The pseudo-element is not generated.
Computes to none for the :before and :after pseudo-elements.
Text content.
<uri> url()
The value is a URI that designates an external resource (such as an image). If the resource or image can't be displayed, it is either ignored or some placeholder shows up.
Counters may be specified with two different functions: 'counter()' or 'counters()'. The former 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 this pseudo-element; it is formatted in the indicated style ('decimal' by default). The latter 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 this pseudo-element, from outermost to innermost separated by the specified string. The counters are rendered in the indicated style ('decimal' by default). See the section on automatic counters and numbering for more information. The name must not be 'none', 'inherit' or 'initial'. Such a name causes the declaration to be ignored.
Returns 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.


q:lang(en) { quotes: '"' '"' "'" "'" }
q:before   { content: open-quote }
q:after    { content: close-quote }
h1:before  { content: "Chapter: "; }
/* content accepts multiple values */
a:before   { content: url( " EXAMPLE: ";
             font:    x-small Arial,freeSans,sans-serif;
             color:   gray;

Code sample - content with multiple values adding an icon before a link


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


    content: url( " EXAMPLE: ";
    font:    x-small Arial,freeSans,sans-serif;
    color:   gray;

Code sample - adding an icon after text in a custom list


  <ul class="brightIdea">
    <li>This is my first idea</li>
    <li>and another good idea</li>


/* first import the icon from a suitable site */
@import url(;
.brightIdea li:after{
    content: '\1f4a1';
    font-family: 'entypo', sans-serif;

Code Sample - class based example


<h2>Paperback best sellers</h2>
    <li>Political thriller</li>
    <li class="newEntry">Halloween Stories</li>
    <li>My Biography</li>    
    <li class="newEntry">Vampire Romance</li>


/* use a class rather that an element selector to give more flexibility.
Simple string example, but don't forget add a leading space in the text string
for spacing purposes  */
.newEntry:after {
    content: " New!";
    color: red;


Desktop browsers

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support1.01.0 (1.7 or earlier)
url() support1.01.0 (1.7 or earlier)

Mobile browsers

FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support1.01.0 (1.0)

Relative articles