English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Complete List of CSS Properties

CSS content property usage and examples

CSS content property and ::before and ::afterPseudo-elementCombined usage to generate content within elements.

The following table provides usage instructions and version history of this attribute, as well as its syntax in JavaScript scripts.

Default value:normal
Applies to:::before and ::after Pseudo-element
Inheritance:None
Animated by:No.See also Animation properties.
Version:CSS 2,3
JavaScript syntax:object.style.content="counter"

The syntax of using content

The syntax of this attribute is as follows:

content: normal | none | counter | string | url(url) | attr(attribute) | open-quote | close-quote | no-open-quote | no-close-quote | initial | inherit

The following example demonstrates how to use the content attribute.

  h1::before {
   content: "Chapter: ";
   display: inline;
  }
Test to see‹/›

Note:display CSS attribute controls whether the content generated by the content attribute is placed in a block box or an inline box.

Attribute Value

The following table describes the value of this attribute.

ValueDescription
normalfor :before and :after Pseudo-element,It does not calculate any value. This is the default value.
nonereferred to asPseudo-elementNo production.
counterThis value will set content to the counter. For more information, please seecounter-resetandcounter-incrementAttribute.
stringInsert the specified string (text content).
url(url)The value url() specifies external resources (such as images). If the resource or image cannot be displayed, it will be ignored or some placeholder will be displayed.
attr(attribute)

This function inserts the specified attribute value before or after the selected element. If the selected element's subject does not have the specified attribute, an empty string will be inserted.

Note:   The attribute name should not be quoted.

open-quoteInsert the left quotation mark. These values will be replaced by the appropriate strings in the quotes attribute.
close-quoteInsert the right quotation mark. These values will be replaced by the appropriate strings in the quotes attribute.
no-open-quoteDo not display the opening quotation mark, but increase (decrease) the nesting level of the quotation marks.
no-close-quoteDo not display the right quotation mark, but increase (decrease) the nesting level of the quotation marks.
initialSet this attribute to its default value.
inheritIf specified, the associated element uses the content attribute value of its parent element.

Browser Compatibility

Browser compatibility of the content attribute, the numbers in the following table represent the minimum version number of the browsers that support this attribute; all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 8+

  • Apple Safari 1+

  • Opera 4+

Warning: Internet Explorer 7and earlier versions do not support the content attribute. IE8Not supported inSupports only when a valid value is specified.

For Further Reading

Please refer to the following tutorials:CSS Pseudo-elements.

Related Attributes:counter-reset,counter-increment.