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 value | normal |
---|---|
Applies to |
::before and ::after pseudo-elements
|
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. |
Animation type | discrete |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
/* Keywords that cannot be combined with other values */ content: normal; content: none; /* <string> value, non-latin characters must be encoded */ /* e.g. \00A0 for */ content: 'prefix'; /* <uri> value */ content: url(http://www.example.com/test.png); /* <counter> values */ content: chapter_counter; /* 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;
none
normal
none
for the :before
and :after
pseudo-elements.<string>
<uri>
or url()
<counter>
attr(X)
open-quote
| close-quote
quotes
property.no-open-quote
| no-close-quote
[ <image> , ]* [ normal | none | <content-list> ] [/ <string> ]?where
<image> = <url> | <image()> | <image-set()> | <element()> | <cross-fade()> | <gradient>
<content-list> = [ <string> | contents | <url> | <quote> | document-url | <target> | <leader()> ]+where
<image()> = image( [ [ <image> | <string> ]? , <color>? ]! )
<image-set()> = image-set( <image-set-option># )
<element()> = element( <id-selector> )
<cross-fade()> = cross-fade( <cf-mixing-image> , <cf-final-image>? )
<gradient> = <linear-gradient()> | <repeating-linear-gradient()> | <radial-gradient()> | <repeating-radial-gradient()>
<quote> = open-quote | close-quote | no-open-quote | no-close-quote
<target> = <target-counter()> | <target-counters()> | <target-text()>
<leader()> = leader( dotted | solid | space | <string> )where
<color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color>
<image-set-option> = [ <image> | <string> ] <resolution>
<cf-mixing-image> = <percentage>? && <image>
<cf-final-image> = <image> | <color>
<linear-gradient()> = linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
<repeating-linear-gradient()> = repeating-linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
<radial-gradient()> = radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
<repeating-radial-gradient()> = repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
<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 ] ]? )where
<rgb()> = rgb( <rgb-component>#{3} )
<rgba()> = rgba( <rgb-component>#{3} , <alpha-value> )
<hsl()> = hsl( <hue>, <percentage>, <percentage> )
<hsla()> = hsla( <hue>, <percentage>, <percentage>, <alpha-value> )
<named-color> = transparent | aliceblue | antiquewhite | aqua | aquamarine | azure | beige | bisque | black | blanchedalmond | blue | blueviolet | brown | burlywood | cadetblue | chartreuse | chocolate | coral | cornflowerblue | cornsilk | crimson | cyan | darkblue | darkcyan | darkgoldenrod | darkgray | darkgreen | darkgrey | darkkhaki | darkmagenta | darkolivegreen | darkorange | darkorchid | darkred | darksalmon | darkseagreen | darkslateblue | darkslategray | darkslategrey | darkturquoise | darkviolet | deeppink | deepskyblue | dimgray | dimgrey | dodgerblue | firebrick | floralwhite | forestgreen | fuchsia | gainsboro | ghostwhite | gold | goldenrod | gray | green | greenyellow | grey | honeydew | hotpink | indianred | indigo | ivory | khaki | lavender | lavenderblush | lawngreen | lemonchiffon | lightblue | lightcoral | lightcyan | lightgoldenrodyellow | lightgray | lightgreen | lightgrey | lightpink | lightsalmon | lightseagreen | lightskyblue | lightslategray | lightslategrey | lightsteelblue | lightyellow | lime | limegreen | linen | magenta | maroon | mediumaquamarine | mediumblue | mediumorchid | mediumpurple | mediumseagreen | mediumslateblue | mediumspringgreen | mediumturquoise | mediumvioletred | midnightblue | mintcream | mistyrose | moccasin | navajowhite | navy | oldlace | olive | olivedrab | orange | orangered | orchid | palegoldenrod | palegreen | paleturquoise | palevioletred | papayawhip | peachpuff | peru | pink | plum | powderblue | purple | rebeccapurple | red | rosybrown | royalblue | saddlebrown | salmon | sandybrown | seagreen | seashell | sienna | silver | skyblue | slateblue | slategray | slategrey | snow | springgreen | steelblue | tan | teal | thistle | tomato | turquoise | violet | wheat | white | whitesmoke | yellow | yellowgreen
<deprecated-system-color> = ActiveBorder | ActiveCaption | AppWorkspace | Background | ButtonFace | ButtonHighlight | ButtonShadow | ButtonText | CaptionText | GrayText | Highlight | HighlightText | InactiveBorder | InactiveCaption | InactiveCaptionText | InfoBackground | InfoText | Menu | MenuText | Scrollbar | ThreeDDarkShadow | ThreeDFace | ThreeDHighlight | ThreeDLightShadow | ThreeDShadow | Window | WindowFrame | WindowText
<side-or-corner> = [ left | right ] || [ top | bottom ]
<color-stop-list> = <color-stop>{2,}
<ending-shape> = circle | ellipse
<size> = closest-side | farthest-side | closest-corner | farthest-corner | <length> | <length-percentage>{2}
<position> = [[ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] | [ center | [ left | right ] <length-percentage>? ] && [ center | [ top | bottom ] <length-percentage>? ]]
<counter-style> = <counter-style-name> | symbols()where
<rgb-component> = <integer> | <percentage>
<alpha-value> = <number>
<hue> = <number>
<color-stop> = <color> <length-percentage>?
<length-percentage> = <length> | <percentage>
<counter-style-name> = <custom-ident>
<h1>5</h1> <p> We shall start this with a quote from 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> Here we shall quote 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> And so, we can infer that contributing to the open web, can protect our own individual experiences on it. </p>
q { color: #00008B; font-style: italic; } q::before { content: open-quote } q::after { content: close-quote } h1::before { content: "Chapter "; }
<a href="http://www.mozilla.org/en-US/">Home Page</a>
a::before{ content: url(https://mozorg.cdn.mozilla.net/media/img/favicon.ico) " MOZILLA: "; font: x-small Arial,freeSans,sans-serif; color: gray; }
<h2>Paperback best sellers</h2> <ol> <li>Political thriller</li> <li class="newEntry">Halloween Stories</li> <li>My Biography</li> <li class="newEntry">Vampire Romance</li> </ol>
/* use a class rather that an element selector to give more flexibility. Below is a simple string example, but don't forget add a leading space in the text string for spacing purposes */ .newEntry::after { content: " New!"; color: red; }
<ul> <li><a id="moz" href="http://www.mozilla.org/"> Mozilla Home Page</a></li> <li><a id="mdn" href="https://developer.mozilla.org/"> Mozilla Developer Network</a></li> </ul>
a { text-decoration: none; border-bottom: 3px dotted navy; } a::after { content: " (" attr(id) ")"; } #moz::before { content:url(https://mozorg.cdn.mozilla.net/media/img/favicon.ico) ; } #mdn::before { content:url(https://mdn.mozillademos.org/files/7691/mdn-favicon16.png) ; } li { margin: 1em; }
Specification | Status | Comment |
---|---|---|
CSS Generated Content Module Level 3 The definition of 'content' in that specification. | Working Draft | |
CSS Level 2 (Revision 1) The definition of 'content' in that specification. | Recommendation | Initial definition |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 1.0 | (Yes) | 1.0 (1.7 or earlier) | 8.0 | 4.0 | 1.0 |
url() support | 1.0 | ? | 1.0 (1.7 or earlier) | 8.0 | 7.0 | 1.0 |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 1.0 | (Yes) | 1.0 (1.0) | 8.0 | 9.5 | 1.0 |
url() support | ? | ? | ? | ? | ? | ? |
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/content