English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The HTML <th> tag defines a header cell that can appear in the first row of an HTML table. Browsers will present the text found within the <th> tag as bold, centered text. This tag is also commonly referred to as the <th> element.
HTML table with two header cells and two data cells:
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>HTML th tag usage (Basic Tutorial Website oldtoolbag.com)</title> </head> <body> <table border="1"> <tr> <th>Column 1 Heading</th> <th>Column 2 Heading</th> <th>Column 3 Heading</th> </tr> <tr> <td>Data in Column> 1, Row 2</td> <td>Data in Column> 2, Row 2</td> <td>Data in Column> 3, Row 2</td> </tr> </table> </body> </html>Test to see ‹/›
In this HTML5In the document example, we used the <table> tag to create a table that has3columns and2rows.1rows.3Cells are defined using <th> tags to define table header cells. The row in this table has2Rows are defined using the <td> tag to define standard table cells.
IEFirefoxOperaChromeSafari
All mainstream browsers support the <th> tag.
<th> tag defines the header cell in an HTML table.
HTML tables have two types of cells:
Header cell - Contains header information (created by <th> element)
standard cell - Contains data (by <td> element creation)
The text in the <th> element is usually bold and centered.
The text in the <td> element is usually left-aligned plain text.
<th> tag is a title cell that can appear in the first row of an HTML table. You can define the <th> tag within the <thead> tag, which has some browser advantages, but it is optional.
Tip:If you need to span content across multiple rows or columns, please use the colspan and rowspan attributes!
HTML 5 No longer supports HTML 4.01 Some attributes in
Attribute | Value | Description |
---|---|---|
abbr | text | HTML5 Not supported. Define the abbreviated version of the content in the header cell. |
align | left right center justify char | HTML5 Not supported. Define the horizontal alignment method of the content in the header cell. |
axis | category_name | HTML5 Not supported. Classify the header cell. |
bgcolor | rgb(x,x,x) #xxxxxx colorname | HTML5 Not supported. HTML 4.01 Deprecated. Define the background color of the header cell. |
char | character | HTML5 Not supported. Define which character to align the content according to. |
charoff | number | HTML5 Not supported. Define the offset of the alignment character. |
colspan | number | Define the number of columns that the header cell can span. |
headers | header_id | Define one or more header cells associated with the header cell. |
height | pixels % | HTML5 Not supported. HTML 4.01 Deprecated. Define the height of the header cell. |
nowrap | nowrap | HTML5 Not supported. HTML 4.01 Deprecated. Define whether the content in the header cell is wrapped. |
rowspan | number | Define the number of rows that the header cell can span. |
scope | col colgroup row rowgroup | Specifies whether the header cell is a header of a row, column, row group, or column group. |
valign | top middle bottom baseline | HTML5 Not supported. Specifies the vertical alignment of the header cell content. |
width | pixels % | HTML5 Not supported. HTML 4.01 Deprecated. Specifies the width of the header cell. |
<th> tag supports HTML Global Attributes.
<th> tag supports all HTML Event Attributes.
Table Cells Spanning Rows or Columns
This example demonstrates how to define table cells that span rows or columns.
Tags within Tables
This example demonstrates how to display elements within different elements.
Cell Padding
This example demonstrates how to use Cell padding to create space between cell content and its border.
Cell Spacing
This example demonstrates how to use Cell spacing to increase the distance between cells.
HTML Tutorial:HTML Tables
HTML DOM Reference Manual:Th Object