Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

HTML <th> Tag


Example

A simple HTML table with three rows, two header cells and four data cells:

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The <th> tag defines a header cell in an HTML table.

An HTML table has two kinds of cells:

  • Header cells - contains header information (created with the <th> element)
  • Data cells - contains data (created with the <td> element)

The text in <th> elements are bold and centered by default.

The text in <td> elements are regular and left-aligned by default.


Browser Support

Element
<th> Yes Yes Yes Yes Yes

Attributes

Attribute Value Description
abbr text Specifies an abbreviated version of the content in a header cell
colspan number Specifies the number of columns a header cell should span
headers header_id Specifies one or more header cells a cell is related to
rowspan number Specifies the number of rows a header cell should span
scope col
colgroup
row
rowgroup
Specifies whether a header cell is a header for a column, row, or group of columns or rows

Global Attributes

The <th> tag also supports the Global Attributes in HTML.


Event Attributes

The <th> tag also supports the Event Attributes in HTML.



More Examples

Example

How to align content inside <th> (with CSS):

<table style="width:100%">
  <tr>
    <th style="text-align:left">Month</th>
    <th style="text-align:left">Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>
Try it Yourself »

Example

How to add background-color to table header cell (with CSS):

<table>
  <tr>
    <th style="background-color:#FF0000">Month</th>
    <th style="background-color:#00FF00">Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
 </table>
Try it Yourself »

Example

How to set the height of a table header cell (with CSS):

<table>
  <tr>
    <th style="height:100px">Month</th>
    <th style="height:100px">Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>
Try it Yourself »

Example

How to specify no word-wrapping in table header cell (with CSS):

<table>
  <tr>
    <th>Month</th>
    <th style="white-space:nowrap">My Savings for a new car</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>
Try it Yourself »

Example

How to vertical align content inside <th> (with CSS):

<table style="width:50%;">
  <tr style="height:100px">
    <th style="vertical-align:bottom">Month</th>
    <th style="vertical-align:bottom">Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>
Try it Yourself »

Example

How to set the width of a table header cell (with CSS):

<table style="width:100%">
  <tr>
    <th style="width:70%">Month</th>
    <th style="width:30%">Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>
Try it Yourself »

Example

How to create table headers:

<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th>Phone</th>
  </tr>
  <tr>
    <td>John Doe</td>
    <td>[email protected]</td>
    <td>123-45-678</td>
  </tr>
</table>
Try it Yourself »

Example

How to create a table with a caption:

<table>
  <caption>Monthly savings</caption>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>
Try it Yourself »

Example

How to define table cells that span more than one row or one column:

<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th colspan="2">Phone</th>
  </tr>
  <tr>
    <td>John Doe</td>
    <td>[email protected]</td>
    <td>123-45-678</td>
    <td>212-00-546</td>
  </tr>
</table>
Try it Yourself »

Related Pages

HTML tutorial: HTML Tables

HTML DOM reference: TableHeader Object

CSS Tutorial: Styling Tables


Default CSS Settings

Most browsers will display the <th> element with the following default values:

th {
  display: table-cell;
  vertical-align: inherit;
  font-weight: bold;
  text-align: center;
}


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.