blob: 793768c2d131e7dad3214c4d4204cc2590cc7339 (
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
|
<header><h1><caption>: The Table Caption element</h1></header><div class="section-content"><p>The <code><caption></code> <a href="../index">HTML</a> element specifies the caption (or title) of a table.</p></div>
<h2 id="try_it">Try it</h2>
<div class="section-content"><iframe class="interactive is-tabbed-taller-height" height="200" src="https://interactive-examples.mdn.mozilla.net/pages/tabbed/caption.html" title="MDN Web Docs Interactive Example" loading="lazy"></iframe></div>
<h2 id="attributes">Attributes</h2>
<div class="section-content"><p>This element includes the <a href="../global_attributes">global attributes</a>.</p></div>
<h3 id="deprecated_attributes">Deprecated attributes</h3>
<div class="section-content">
<p>The following attributes are deprecated and should not be used. They are documented below for reference when updating existing code and for historical interest only.</p> <dl> <dt id="align">
<a href="#align"><code>align</code></a> <abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr>
</dt> <dd> <p>This <a href="https://developer.mozilla.org/en-US/docs/Glossary/Enumerated">enumerated</a> attribute indicates how the caption must be aligned with respect to the table. It may have one of the following values:</p> <dl> <dt id="left"><a href="#left"><code>left</code></a></dt> <dd> <p>The caption is displayed to the left of the table.</p> </dd> <dt id="top"><a href="#top"><code>top</code></a></dt> <dd> <p>The caption is displayed above the table.</p> </dd> <dt id="right"><a href="#right"><code>right</code></a></dt> <dd> <p>The caption is displayed to the right of the table.</p> </dd> <dt id="bottom"><a href="#bottom"><code>bottom</code></a></dt> <dd> <p>The caption is displayed below the table.</p> </dd> </dl> <div class="notecard warning" id="sect1"> <p><strong>Warning:</strong> Do not use this attribute, as it has been deprecated. The <a href="caption" aria-current="page"><code><caption></code></a> element should be styled using the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS">CSS</a> properties <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/caption-side"><code>caption-side</code></a> and <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-align"><code>text-align</code></a>.</p> </div> </dd> </dl>
</div>
<h2 id="usage_notes">Usage notes</h2>
<div class="section-content">
<p>If used, the <code><caption></code> element must be the first child of its parent <a href="table"><code><table></code></a> element.</p> <p>When the <code><table></code> element that contains the <code><caption></code> is the only descendant of a <a href="figure"><code><figure></code></a> element, you should use the <a href="figcaption"><code><figcaption></code></a> element instead of <code><caption></code>.</p> <p>A <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-color"><code>background-color</code></a> on the table will not include the caption. Add a <code>background-color</code> to the <code><caption></code> element as well if you want the same color to be behind both.</p>
</div>
<h2 id="example">Example</h2>
<div class="section-content">
<p>This simple example presents a table that includes a caption.</p> <div class="code-example">
<p class="example-header"><span class="language-name">html</span></p>
<pre data-signature="Qj/fk8WT+LS0IFQz7N0dFGfEQTpB9teHn1jyllNTA0c=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>table</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>caption</span><span class="token punctuation">></span></span>
Example Caption
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>caption</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>tr</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>th</span><span class="token punctuation">></span></span>Login<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>th</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>th</span><span class="token punctuation">></span></span>Email<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>th</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>tr</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>tr</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>td</span><span class="token punctuation">></span></span>user1<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>td</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>td</span><span class="token punctuation">></span></span>user1@sample.com<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>td</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>tr</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>tr</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>td</span><span class="token punctuation">></span></span>user2<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>td</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>td</span><span class="token punctuation">></span></span>user2@sample.com<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>td</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>tr</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>table</span><span class="token punctuation">></span></span>
</pre>
</div>
<div class="code-example" id="sect2">
<iframe class="sample-code-frame" title="Example sample" id="frame_example" width="650" height="100" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/caption/runner.html?id=example" loading="lazy"></iframe>
</div>
</div>
<h2 id="technical_summary">Technical summary</h2>
<div class="section-content"><figure class="table-container"><div class="_table"><table class="properties"> <tbody> <tr> <th scope="row"><a href="../content_categories">Content categories</a></th> <td>None.</td> </tr> <tr> <th scope="row">Permitted content</th> <td>
<a href="../content_categories#flow_content">Flow content</a>.</td> </tr> <tr> <th scope="row">Tag omission</th> <td> The end tag can be omitted if the element is not immediately followed by ASCII whitespace or a comment. </td> </tr> <tr> <th scope="row">Permitted parents</th> <td>A <a href="table"><code><table></code></a> element, as its first descendant.</td> </tr> <tr> <th scope="row">Implicit ARIA role</th> <td><code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/structural_roles#structural_roles_with_html_equivalents">caption</a></code></td> </tr> <tr> <th scope="row">Permitted ARIA roles</th> <td>No <code>role</code> permitted</td> </tr> <tr> <th scope="row">DOM interface</th> <td><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCaptionElement"><code>HTMLTableCaptionElement</code></a></td> </tr> </tbody> </table></div></figure></div>
<h2 id="specifications">Specifications</h2>
<div class="_table"><table class="standard-table">
<thead><tr><th scope="col">Specification</th></tr></thead>
<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/tables.html#the-caption-element">HTML Standard <br><small># the-caption-element</small></a></td></tr></tbody>
</table></div>
<h2 id="browser_compatibility">Browser compatibility</h2>
<div class="_table"><table>
<thead>
<tr id="bct-browser-type">
<th></th>
<th colspan="6">Desktop</th>
<th colspan="6">Mobile</th>
</tr>
<tr id="bct-browsers">
<th></th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
<th>WebView Android</th>
<th>Chrome Android</th>
<th>Firefox for Android</th>
<th>Opera Android</th>
<th>Safari on IOS</th>
<th>Samsung Internet</th>
</tr>
</thead>
<tbody>
<tr>
<th><code>caption</code></th>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">12</td>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">Yes</td>
<td class="bc-supports-yes">15</td>
<td class="bc-supports-yes">≤4</td>
<td class="bc-supports-yes">4.4</td>
<td class="bc-supports-yes">18</td>
<td class="bc-supports-yes">4</td>
<td class="bc-supports-yes">14</td>
<td class="bc-supports-yes">≤3.2</td>
<td class="bc-supports-yes">1.0</td>
</tr>
<tr>
<th><code>align</code></th>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">12</td>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">Yes</td>
<td class="bc-supports-yes">15</td>
<td class="bc-supports-yes">≤4</td>
<td class="bc-supports-yes">4.4</td>
<td class="bc-supports-yes">18</td>
<td class="bc-supports-yes">4</td>
<td class="bc-supports-yes">14</td>
<td class="bc-supports-yes">≤3.2</td>
<td class="bc-supports-yes">1.0</td>
</tr>
</tbody>
</table></div>
<h2 id="see_also">See also</h2>
<div class="section-content"><ul> <li>CSS properties that may be specially useful to style the <a href="caption" aria-current="page"><code><caption></code></a> element: <ul> <li>
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-align"><code>text-align</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/caption-side"><code>caption-side</code></a>.</li> </ul> </li> </ul></div><div class="_attribution">
<p class="_attribution-p">
© 2005–2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br>
<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption</a>
</p>
</div>
|