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
|
---
title: <th>
slug: Web/HTML/Element/th
tags:
- HTML
- 레퍼런스
- 요소
- 웹
- 표
translation_of: Web/HTML/Element/th
---
<div>{{HTMLRef}}</div>
<p><span class="seoSummary">The <strong>HTML <code><th></code> element</strong> defines a cell as header of a group of table cells. The exact nature of this group is defined by the {{htmlattrxref("scope", "th")}} and {{htmlattrxref("headers", "th")}} attributes.</span></p>
<div>{{EmbedInteractiveExample("pages/tabbed/th.html","tabbed-taller")}}</div>
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples </a> and send us a pull request.</p>
<table class="properties">
<tbody>
<tr>
<th scope="row"><a href="/en-US/docs/Web/Guide/HTML/Content_categories">Content categories</a></th>
<td>None.</td>
</tr>
<tr>
<th scope="row">Permitted content</th>
<td><a href="/en-US/docs/Web/Guide/HTML/Content_categories#Flow_content">Flow content</a>, but with no header, footer, sectioning content, or heading content descendants.</td>
</tr>
<tr>
<th scope="row">Tag omission</th>
<td>The start tag is mandatory.<br>
The end tag may be omitted, if it is immediately followed by a {{HTMLElement("th")}} or {{HTMLElement("td")}} element or if there are no more data in its parent element.</td>
</tr>
<tr>
<th scope="row">Permitted parents</th>
<td>A {{HTMLElement("tr")}} element.</td>
</tr>
<tr>
<th scope="row">Permitted ARIA roles</th>
<td>Any</td>
</tr>
<tr>
<th scope="row">DOM interface</th>
<td>{{domxref("HTMLTableHeaderCellElement")}}</td>
</tr>
</tbody>
</table>
<h2 id="Attributes">Attributes</h2>
<p>This element includes the <a href="/en-US/docs/Web/HTML/Global_attributes">global attributes</a>.</p>
<dl>
<dt>{{htmlattrdef("abbr")}}</dt>
<dd>This attribute contains a short abbreviated description of the cell's content. Some user-agents, such as speech readers, may present this description before the content itself.</dd>
<dt>{{htmlattrdef("align")}} {{obsolete_inline("html5")}}</dt>
<dd>This enumerated attribute specifies how the cell content's horizontal alignment will be handled. Possible values are:
<ul>
<li><code>left</code>: The content is aligned to the left of the cell.</li>
<li><code>center</code>: The content is centered in the cell.</li>
<li><code>right</code>: The content is aligned to the right of the cell.</li>
<li><code>justify</code> (with text only): The content is stretched out inside the cell so that it covers its entire width.</li>
<li><code>char</code> (with text only): The content is aligned to a character inside the <code><th></code> element with minimal offset. This character is defined by the {{htmlattrxref("char", "th")}} and {{htmlattrxref("charoff", "th")}} attributes.</li>
</ul>
<p>The default value when this attribute is not specified is <code>left</code>.</p>
<div class="note"><strong>Note: </strong>Do not use this attribute as it is obsolete in the latest standard.
<ul>
<li>To achieve the same effect as the <code>left</code>, <code>center</code>, <code>right</code> or <code>justify</code> values, apply the CSS {{cssxref("text-align")}} property to the element.</li>
<li>To achieve the same effect as the <code>char</code> value, give the {{cssxref("text-align")}} property the same value you would use for the {{htmlattrxref("char", "th")}}. {{unimplemented_inline}} in CSS3.</li>
</ul>
</div>
</dd>
<dt>{{htmlattrdef("axis")}} {{obsolete_inline("html5")}}</dt>
<dd>This attribute contains a list of space-separated strings. Each string is the <code>id</code> of a group of cells that this header applies to.
<div class="note"><strong>Note:</strong> Do not use this attribute as it is obsolete in the latest standard: use the {{htmlattrxref("scope", "th")}} attribute instead.</div>
</dd>
<dt>{{htmlattrdef("bgcolor")}} {{Non-standard_inline}}</dt>
<dd>This attribute defines the background color of each cell in a column. It consists of a 6-digit hexadecimal code as defined in <a href="https://www.w3.org/Graphics/Color/sRGB">sRGB</a> and is prefixed by '#'. This attribute may be used with one of sixteen predefined color strings:
<table>
<tbody>
<tr>
<td style="background-color: black; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>black</code> = "#000000"</td>
<td style="background-color: green; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>green</code> = "#008000"</td>
</tr>
<tr>
<td style="background-color: silver; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>silver</code> = "#C0C0C0"</td>
<td style="background-color: lime; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>lime</code> = "#00FF00"</td>
</tr>
<tr>
<td style="background-color: gray; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>gray</code> = "#808080"</td>
<td style="background-color: olive; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>olive</code> = "#808000"</td>
</tr>
<tr>
<td style="background-color: white; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>white</code> = "#FFFFFF"</td>
<td style="background-color: yellow; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>yellow</code> = "#FFFF00"</td>
</tr>
<tr>
<td style="background-color: maroon; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>maroon</code> = "#800000"</td>
<td style="background-color: navy; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>navy</code> = "#000080"</td>
</tr>
<tr>
<td style="background-color: red; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>red</code> = "#FF0000"</td>
<td style="background-color: blue; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>blue</code> = "#0000FF"</td>
</tr>
<tr>
<td style="background-color: purple; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>purple</code> = "#800080"</td>
<td style="background-color: teal; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>teal</code> = "#008080"</td>
</tr>
<tr>
<td style="background-color: fuchsia; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>fuchsia</code> = "#FF00FF"</td>
<td style="background-color: aqua; width: 24px; height: 24px; border: 1px solid black;"> </td>
<td><code>aqua</code> = "#00FFFF"</td>
</tr>
</tbody>
</table>
<div class="note"><strong>Note:</strong> Do not use this attribute, as it is non-standard and only implemented in some versions of Microsoft Internet Explorer: The {{HTMLElement("th")}} element should be styled using <a href="/en-US/docs/Web/CSS">CSS</a>. To create a similar effect use the {{cssxref("background-color")}} property in <a href="/en-US/docs/Web/CSS">CSS</a> instead.</div>
</dd>
</dl>
<dl>
<dt>{{htmlattrdef("char")}} {{obsolete_inline("html5")}}</dt>
<dd>The content in the cell element is aligned to a character. Typical values include a period (.) to align numbers or monetary values. If {{htmlattrxref("align", "th")}} is not set to <code>char</code>, this attribute is ignored.
<div class="note"><strong>Note:</strong> Do not use this attribute as it is obsolete in the latest standard. To achieve the same effect, you can specify the character as the first value of the {{cssxref("text-align")}} property, {{unimplemented_inline}} in CSS3.</div>
</dd>
<dt>{{htmlattrdef("charoff")}} {{obsolete_inline("html5")}}</dt>
<dd>This attribute is used to shift column data to the right of the character specified by the <strong>char</strong> attribute. Its value specifies the length of this shift.
<div class="note"><strong>Note: </strong>Do not use this attribute as it is obsolete in the latest standard.</div>
</dd>
<dt>{{htmlattrdef("colspan")}}</dt>
<dd>This attribute contains a non-negative integer value that indicates for how many columns the cell extends. Its default value is <code>1</code>. Values higher than 1000 will be considered as incorrect and will be set to the default value (1).</dd>
<dt>{{htmlattrdef("headers")}}</dt>
<dd>This attribute contains a list of space-separated strings, each corresponding to the <strong>id</strong> attribute of the {{HTMLElement("th")}} elements that apply to this element.</dd>
<dt>{{htmlattrdef("height")}} {{Deprecated_inline("html 4")}}, {{obsolete_inline("html5")}}</dt>
<dd>This attribute is used to define a recommended cell height.
<div class="note"><strong>Note: </strong>Do not use this attribute as it is obsolete in the latest standard: use the CSS {{cssxref("height")}} property instead.</div>
</dd>
<dt>{{htmlattrdef("rowspan")}}</dt>
<dd>This attribute contains a non-negative integer value that indicates for how many rows the cell extends. Its default value is <code>1</code>; if its value is set to <code>0</code>, it extends until the end of the table section ({{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, even if implicitly defined), that the cell belongs to. Values higher than 65534 are clipped down to 65534.</dd>
<dt>{{htmlattrdef("scope")}}</dt>
<dd>This enumerated attribute defines the cells that the header (defined in the {{HTMLElement("th")}}) element relates to. It may have the following values:
<ul>
<li><code>row</code>: The header relates to all cells of the row it belongs to.</li>
<li><code>col</code>: The header relates to all cells of the column it belongs to.</li>
<li><code>rowgroup</code>: The header belongs to a rowgroup and relates to all of its cells. These cells can be placed to the right or the left of the header, depending on the value of the <code><a href="/en-US/docs/Web/HTML/Global_attributes/dir">dir</a></code> attribute in the {{HTMLElement("table")}} element.</li>
<li><code>colgroup</code>: The header belongs to a colgroup and relates to all of its cells.</li>
<li><code>auto</code></li>
</ul>
<p>The default value when this attribute is not specified is <code>auto</code>.</p>
</dd>
<dt>{{htmlattrdef("valign")}} {{obsolete_inline("html5")}}</dt>
<dd>This attribute specifies how a text is vertically aligned inside a cell. Possible values for this attribute are:
<ul>
<li><code>baseline</code>: Positions the text near the bottom of the cell and aligns it with the <a href="https://en.wikipedia.org/wiki/Baseline_%28typography%29">baseline</a> of the characters instead of the bottom. If characters don't descend below the baseline, the baseline value achieves the same effect as <code>bottom</code>.</li>
<li><code>bottom</code>: Positions the text near the bottom of the cell.</li>
<li><code>middle</code>: Centers the text in the cell.</li>
<li>and <code>top</code>: Positions the text near the top of the cell.</li>
</ul>
<div class="note"><strong>Note:</strong> Do not use this attribute as it is obsolete in the latest standard: use the CSS {{cssxref("vertical-align")}} property instead.</div>
</dd>
<dt>{{htmlattrdef("width")}} {{Deprecated_inline("html 4")}}, {{obsolete_inline("html5")}}</dt>
<dd>This attribute is used to define a recommended cell width. Additional space can be added with the {{domxref("HTMLTableElement.cellSpacing", "cellspacing")}} and {{domxref("HTMLTableElement.cellPadding", "cellpadding")}} properties and the width of the {{HTMLElement("col")}} element can also create extra width. But, if a column's width is too narrow to show a particular cell properly, it will be widened when displayed.
<div class="note"><strong>Note:</strong> Do not use this attribute as it is obsolete in the latest standard: use the CSS {{cssxref("width")}} property instead.</div>
</dd>
</dl>
<h2 id="Examples">Examples</h2>
<p>See {{HTMLElement("table")}} for examples on <code><th></code>.</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('HTML WHATWG','tables.html#the-th-element','th element')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('HTML5 W3C','tabular-data.html#the-th-element','th element')}}</td>
<td>{{Spec2('HTML5 W3C')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("html.elements.th")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li>Other table-related HTML Elements: {{HTMLElement("caption")}}, {{HTMLElement("col")}}, {{HTMLElement("colgroup")}}, {{HTMLElement("table")}}, {{HTMLElement("tbody")}}, {{HTMLElement("td")}}, {{HTMLElement("tfoot")}}, {{HTMLElement("thead")}}, {{HTMLElement("tr")}}.</li>
</ul>
|