Description
The HTML element <th>
is used to define a table header cell.
A table cell can contain two types of information.
- Element
<th>
for header information, which is rendered and displayed with bold font by the browsers. - Element
<td>
for data, which is rendered and displayed as a regular text. - Elements
<th>
and<td>
are rendered and displayed differently by the browsers as mentioned above, without any additional CSS.
The below table summarizes its usage.
Usage Details | |
Placement | It is a child of <tr> element. |
Contents | It can contain Block elements, Inline elements, and text. |
Tags | Both opening and closing tags are required. |
Versions | HTML 3.2, 4, 4.01, 5 |
Syntax
Here is the basic syntax of the <th>
element.
<th>...</th>
Examples
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example - HTML Element th</title>
</head>
<body>
<table>
<caption>Products List</caption>
<thead>
<tr>
<th>Product</th>
<th>Sales</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bread</td>
<td>10000</td>
</tr>
<tr>
<td>Butter</td>
<td>3000</td>
</tr>
</tbody>
</table>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <th>
element.
Attribute Type | Details |
Element-Specific Attributes | The tag <th> has some element-specific attributes listed in the below table. |
Global Attributes | Like all other HTML tags, the tag <th> supports the HTML Global Attributes. |
Event Attributes | The tag <th> also supports the HTML Event Attributes. |
Here is a list of attributes that are specific to the <th>
element.
Attribute | Value | Required | Description |
abbr |
text | No | Provides a short abbreviated description of the header cell's content. |
align |
left, right, center, justify, char | No | Obsolete Specifies the alignment of header cell content. |
axis |
text | No | Obsolete Categorizes a group of related header cells. |
bgcolor |
color | No | Obsolete Sets the background color of a header cell. |
char |
character | No | Obsolete Sets the character to which header cell contents should align. |
charoff |
number | No | Obsolete Defines the number of characters by which header cell contents will be offset from the alignment characters specified by the char attribute. |
colspan |
number | No | Specifies the number of columns spanned by the current header cell. |
headers |
header-id | No | Specifies one or more header cells a cell is related to. |
height |
length | No | Obsolete Sets the height of the table header cell. |
nowrap |
nowrap |
No | Obsolete This boolean attribute tells the browser to disable automatic text wrapping for this header cell. |
rowspan |
number | No | Specifies the number of rows spanned by the current header cell. |
scope |
col, colgroup, row, rowgroup | No | Specifies the set of data cells for which the current header cell provides header information. |
sorted |
reversed, number | No | Specifies the sort direction of a column. |
valign |
top, middle, bottom, baseline | No | Obsolete Specifies the vertical alignment of content within a header cell. |
width |
length | No | Obsolete Sets the width of a header cell. |
Browser Compatibility
The tag <th>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 2+
- Firefox 1+
- Apple Safari 1+
- Opera 4+