aboutsummaryrefslogtreecommitdiff
path: root/files/vi/web/css/content/index.html
blob: 188f634136c70e068730ec4a07e683208fb4e4ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
---
title: content
slug: Web/CSS/content
translation_of: Web/CSS/content
---
<div>{{CSSRef}}</div>

<p class="summary">The <strong><code>content</code></strong> <a href="/en-US/docs/Web/CSS">CSS</a> property replaces an element with a generated value. Objects inserted using the <code>content</code> property are <strong>anonymous <a href="/en-US/docs/Web/CSS/Replaced_element">replaced elements</a></strong><em>.</em></p>

<pre class="brush:css no-line-numbers notranslate">/* Keywords that cannot be combined with other values */
content: normal;
content: none;

/* <a href="/en-US/docs/Web/CSS/image">&lt;image&gt;</a> values */
content: url("http://www.example.com/test.png");
content: linear-gradient(#e66465, #9198e5);

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

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

/* &lt;string&gt; value */
content: "prefix";

/* <a href="/en-US/docs/Web/CSS/counter">&lt;counter&gt;</a> values, optionally with <a href="/en-US/docs/Web/CSS/list-style-type">&lt;list-style-type&gt; </a>*/
content: counter(chapter_counter);
content: counter(chapter_counter, upper-roman);
content: counters(section_counter, ".");
content: counters(section_counter, ".", <code>decimal-leading-zero</code>);

/* <a href="/en-US/docs/Web/CSS/attr">attr()</a> 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;
</pre>

<h2 id="Syntax">Syntax</h2>

<h3 id="Values">Values</h3>

<dl>
 <dt><code>none</code></dt>
 <dd>The pseudo-element is not generated.</dd>
 <dt><code>normal</code></dt>
 <dd>Computes to <code>none</code> for the <code>::before</code> and <code>::after</code> pseudo-elements.</dd>
 <dt>{{cssxref("&lt;string&gt;")}}</dt>
 <dd>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, <code>\000A9</code> represents the copyright symbol.</dd>
 <dt>{{cssxref("&lt;image&gt;")}}</dt>
 <dd>An {{cssxref("&lt;image&gt;")}}, denoted by the {{cssxref("&lt;url&gt;")}} or {{cssxref("&lt;gradient&gt;")}} data type, or part of the webpage, defined by the {{cssxref("element", "element()")}} function, denoting the content to display.</dd>
 <dt>{{cssxref("&lt;counter&gt;")}}</dt>
 <dd>The value of a <a href="/en-US/docs/Web/CSS/CSS_Lists_and_Counters/Using_CSS_counters">CSS counter</a>, generally a number produced by computations defined by {{cssxref("&lt;counter-reset&gt;")}} and {{cssxref("&lt;counter-increment&gt;")}} properies. It can be displayed using either the {{cssxref("counter")}} or {{cssxref("counters")}} function.</dd>
 <dd>
 <p>The {{cssxref("counter")}} function has two forms: 'counter(<var>name</var>)' or 'counter(<var>name</var>, 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 {{cssxref("&lt;list-style-type&gt;")}} (<code>decimal</code> by default).</p>

 <p>The {{cssxref("counters")}} function also has two forms: 'counters(<var>name</var>, <var>string</var>)' or 'counters(<var>name</var>, <var>string</var>, <var>style</var>)'. 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 {{cssxref("&lt;list-style-type&gt;")}} (<code>decimal</code> by default).</p>
 </dd>
 <dt><code>attr(x)</code></dt>
 <dd>The value of the element's attribute <code>x</code> as a string. If there is no attribute <code>x</code>, an empty string is returned. The case-sensitivity of attribute names depends on the document language.</dd>
 <dt><code>open-quote</code> | <code>close-quote</code></dt>
 <dd>These values are replaced by the appropriate string from the {{cssxref("quotes")}} property.</dd>
 <dt><code>no-open-quote</code> | <code>no-close-quote</code></dt>
 <dd>Introduces no content, but increments (decrements) the level of nesting for quotes.</dd>
</dl>

<h2 id="Accessibility_concerns">Accessibility concerns</h2>

<p>CSS-generated content is not included in the <a href="/en-US/docs/Web/API/Document_Object_Model/Introduction">DOM</a>. Because of this, it will not be represented in the <a href="/en-US/docs/Learn/Accessibility/What_is_accessibility#Accessibility_APIs">accessibility tree</a> 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.</p>

<ul>
 <li><a href="https://tink.uk/accessibility-support-for-css-generated-content/">Accessibility support for CSS generated content – Tink</a></li>
 <li><a href="/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#Guideline_1.3_%E2%80%94_Create_content_that_can_be_presented_in_different_ways">Explanation of WCAG, Guideline 1.3 – MDN</a></li>
 <li><a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/content-structure-separation-programmatic.html">Understanding Success Criterion 1.3.1 | W3C Understanding WCAG 2.0</a></li>
</ul>

<h2 id="Formal_definition">Formal definition</h2>

<p>{{cssinfo}}</p>

<h2 id="Formal_syntax">Formal syntax</h2>

<pre class="syntaxbox notranslate">{{csssyntax}}</pre>

<h2 id="Examples">Examples</h2>

<h3 id="Headings_and_quotes">Headings and quotes</h3>

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

<h4 id="HTML">HTML</h4>

<pre class="brush: html notranslate">&lt;h1&gt;5&lt;/h1&gt;
&lt;p&gt;According to Sir Tim Berners-Lee,
  &lt;q cite="http://www.w3.org/People/Berners-Lee/FAQ.html#Internet"&gt;I was
    lucky enough to invent the Web at the time when the Internet
    already existed - and had for a decade and a half.&lt;/q&gt;
  We must understand that there is nothing fundamentally wrong
  with building on the contributions of others.
&lt;/p&gt;

&lt;h1&gt;6&lt;/h1&gt;
&lt;p&gt;According to the Mozilla Manifesto,
  &lt;q cite="http://www.mozilla.org/en-US/about/manifesto/"&gt;Individuals
    must have the ability to shape the Internet and
    their own experiences on the Internet.&lt;/q&gt;
  Therefore, we can infer that contributing to the open web
  can protect our own individual experiences on it.
&lt;/p&gt;</pre>

<h4 id="CSS">CSS</h4>

<pre class="brush: css notranslate">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 */
}</pre>

<h4 id="Result">Result</h4>

<p>{{EmbedLiveSample('Headings_and_quotes', '100%', 200)}}</p>

<h3 id="Image_combined_with_text">Image combined with text</h3>

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

<h4 id="HTML_2">HTML</h4>

<pre class="brush: html notranslate">&lt;a href="http://www.mozilla.org/en-US/"&gt;Mozilla Home Page&lt;/a&gt;</pre>

<h4 id="CSS_2">CSS</h4>

<pre class="brush: css notranslate">a::before {
  content: url("https://mozorg.cdn.mozilla.net/media/img/favicon.ico") / " MOZILLA: ";
  font: x-small Arial, sans-serif;
  color: gray;
}</pre>

<h4 id="Result_2">Result</h4>

<p>{{EmbedLiveSample('Image_combined_with_text', '100%', 60)}}</p>

<h3 id="Targeting_classes">Targeting classes</h3>

<p>This example inserts additional text after special items in a list.</p>

<h4 id="HTML_3">HTML</h4>

<pre class="brush: html notranslate">&lt;h2&gt;Paperback Best Sellers&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;Political Thriller&lt;/li&gt;
  &lt;li class="new-entry"&gt;Halloween Stories&lt;/li&gt;
  &lt;li&gt;My Biography&lt;/li&gt;
  &lt;li class="new-entry"&gt;Vampire Romance&lt;/li&gt;
&lt;/ol&gt;</pre>

<h4 id="CSS_3">CSS</h4>

<pre class="brush: css notranslate">.new-entry::after {
  content: " New!";  /* The leading space creates separation
                        between the added content and the
                        rest of the content */
  color: red;
}</pre>

<h4 id="Result_3">Result</h4>

<p>{{EmbedLiveSample('Targeting_classes', '100%', 160)}}</p>

<h3 id="Images_and_element_attributes">Images and element attributes</h3>

<p>This example inserts an image before each link, and adds its <code>id</code> attribute after.</p>

<h4 id="HTML_4">HTML</h4>

<pre class="brush: html notranslate">&lt;ul&gt;
  &lt;li&gt;&lt;a id="moz" href="http://www.mozilla.org/"&gt;
    Mozilla Home Page&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a id="mdn" href="https://developer.mozilla.org/"&gt;
    Mozilla Developer Network&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre>

<h4 id="CSS_4">CSS</h4>

<pre class="brush: css notranslate">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;
}
</pre>

<h4 id="Result_4">Result</h4>

<p>{{EmbedLiveSample('Images_and_element_attributes', '100%', 160)}}</p>

<h3 id="Element_replacement">Element replacement</h3>

<p>This example replaces an element's content with an image. You can replace the contents of an element with either a {{cssxref("&lt;url&gt;")}} or an {{cssxref("&lt;image&gt;")}} value. Content added with <code>::before</code> or <code>::after</code> will not be generated as the contents of the element have been replaced.</p>

<h4 id="HTML_5">HTML</h4>

<pre class="brush: html notranslate">&lt;div id="replaced"&gt;Mozilla&lt;/div&gt;
</pre>

<h4 id="CSS_5">CSS</h4>

<pre class="brush: css notranslate">#replaced {
  content: url("https://mdn.mozillademos.org/files/12668/MDN.svg");
}

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

<h4 id="Result_5">Result</h4>

<p>{{EmbedLiveSample('Element_replacement', '100%', 200)}}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("CSS3 Content", "#content-property", "content")}}</td>
   <td>{{Spec2("CSS3 Content")}}</td>
   <td>Adds support for alt-text</td>
  </tr>
  <tr>
   <td>{{SpecName("CSS2.1", "generate.html#content", "content")}}</td>
   <td>{{Spec2("CSS2.1")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("css.properties.content")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/CSS/Replaced_element">Replaced elements</a></li>
 <li>{{Cssxref("::after")}}</li>
 <li>{{Cssxref("::before")}}</li>
 <li>{{Cssxref("::marker")}}</li>
 <li>{{Cssxref("quotes")}}</li>
 <li>{{cssxref("url()", "url()")}} function</li>
</ul>