English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML tag大全

HTML: <th> tag

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.

Online Example

 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.

Browser compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers support the <th> tag.

Tag definition and usage instructions

<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.

Tips and Notes

Tip:If you need to span content across multiple rows or columns, please use the colspan and rowspan attributes!

HTML 4.01 and HTML5between

HTML 5 No longer supports HTML 4.01 Some attributes in

Attribute

AttributeValueDescription
abbrtextHTML5 Not supported. Define the abbreviated version of the content in the header cell.
alignleft
 right
 center
 justify
 char
HTML5 Not supported. Define the horizontal alignment method of the content in the header cell.
axiscategory_nameHTML5 Not supported. Classify the header cell.
bgcolorrgb(x,x,x)
#xxxxxx
colorname
HTML5 Not supported. HTML 4.01 Deprecated. Define the background color of the header cell.
charcharacterHTML5 Not supported. Define which character to align the content according to.
charoffnumberHTML5 Not supported. Define the offset of the alignment character.
colspannumberDefine the number of columns that the header cell can span.
headersheader_idDefine one or more header cells associated with the header cell.
heightpixels
%
HTML5 Not supported. HTML 4.01 Deprecated. Define the height of the header cell.
nowrapnowrapHTML5 Not supported. HTML 4.01 Deprecated. Define whether the content in the header cell is wrapped.
rowspannumberDefine the number of rows that the header cell can span.
scopecol
 colgroup
 row
 rowgroup
Specifies whether the header cell is a header of a row, column, row group, or column group.
valigntop
 middle
 bottom
 baseline
HTML5 Not supported. Specifies the vertical alignment of the header cell content.
widthpixels
%
HTML5 Not supported. HTML 4.01 Deprecated. Specifies the width of the header cell.

global attributes

<th> tag supports HTML Global Attributes.

event attributes

<th> tag supports all HTML Event Attributes.

More Examples

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.

Related Articles

HTML Tutorial:HTML Tables

HTML DOM Reference Manual:Th Object