Code has been added to clipboard!

HTML th Tag

Reading time 3 min
Published Jun 29, 2017
Updated Oct 15, 2019

HTML th: Main Tips

  • Table header cells are defined using HTML th tags.
  • Their text content is bold and centered by default.
  • A <th> element is usually a child of a <tr> element.
  • Most of the tag-specific attributes are deprecated in HTML5. It's best to use CSS properties for styling.

Defining Header Cells

HTML tables have two types of cells: header and standard. The content of a table cell can span multiple columns or rows.

The HTML th tags define a header cell in a table:

Example
<table>
  <tr>
    <th>Fruits</th>
    <th>Prices</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>$1.26</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>$0.60</td>
  </tr>
</table>

To define the standard cells, use <td> tags. Their content is displayed as regular text.

Common th Tag Attributes

abbr defines a short abbreviated description of the cell's content:

Example
<table>
  <tr>
    <th abbr="fruits">List of Fruits</th>
    <th abbr="prices">Price per Unit of Fruit</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

colspan sets the number of columns a <th> element should span:

Example
<table>
  <tr>
    <th colspan="2">List of Fruit Prices</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

headers defines an ID of a header cell, which a particular header cell is related to:

Example
<table>
  <tr>
    <th id="name" colspan="2">List of Fruit Prices</th>
  </tr>
  <tr>
    <th headers="name">Fruit</th>
    <th headers="name">Price</th>
  </tr>
</table>

rowspan sets the number of rows a <th> element should span:

Example
<table>
  <tr>
    <th>Fruits</th>
    <th>Prices</th>
    <th rowspan="3">Month of June 2017</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.6</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

scope defines whether a header cell is a header for a column, row, or a group of columns or rows:

Example
<table>
  <tr>
    <th scope="col">Fruits</th>
    <th scope="col">Prices</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.6</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

Obsolete Attributes

There's also a lot of attributes that were tag-specific to HTML th, but have been removed in HTML5.

align defined horizontal alignment of the th cell's content:

Example
<table width="100%">
  <tr>
    <th align="left">List of Fruits</th>
    <th align="right">Price per Unit of Fruit</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

Note: instead of align, use CSS text-align property.

axis defined a category for grouping header cells:

Example
<table>
  <tr>
    <th axis="name">Fruits</th>
    <th axis="price">Prices</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

bgcolor set the background color for a header cell:

Example
<table>
  <tr>
    <th bgcolor="yellow">Fruits</th>
    <th bgcolor="#00FF00">Prices</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

Note: instead of bgcolor, use CSS background-color property.

char set the alignment of th cell's content according to the character specified:

Example
<table>
  <tr>
    <th>Fruits</th>
    <th align="char" char=".">Prices €0.00</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

charoff set the number of characters for aligning the content after the character specified by the char attribute:

Example
<table>
  <tr>
    <th>Fruits</th>
    <th align="char" char="." charoff="2">Prices €0.00</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

height set th cell's height:

Example
<table>
  <tr>
    <th height="50px" colspan="2">List of Fruit Prices</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

Note: instead of height, use CSS height property.

nowrap defined that the content inside a header cell should not be wrapped:

Example
<table>
  <tr>
    <th nowrap colspan="2">Prices per Unit of Fruit</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

Note: instead of nowrap, use CSS white-space property.

valign defined vertical alignment of the th cell's content:

Example
<table>
  <tr>
    <th>Fruits</th>
    <th>Prices</th>
    <th rowspan="3" valign="top">Month of June 2017</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

Note: instead of valign, use CSS vertical-align property.

width set th cell's width:

Example
<table>
  <tr>
    <th width="50%">Fruits</th>
    <th width="100px">Prices</th>
  </tr>
  <tr>
    <td>Apple</td>
    <td>€0.60</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>€0.32</td>
  </tr>
</table>

Note: instead of width, use CSS width property.

Browser support

Chrome
1+
Edge
All
Firefox
1+
IE
All
Opera
All
Safari
All

Mobile browser support

Chrome
All
Firefox
4+
Opera
All
Safari
All
Basics
Introduction
Syntax
Editors
Basic Examples
Head Section
<!DOCTYPE>
Tags and Elements
Semantic Elements
Tags Reference
Attributes
Comments
Block and Inline Elements
Forms
Form Elements
Input
Responsive Web Design
Inline Scripts
Uniform Resource Locator
Redirect
XHTML
Geolocation
Drag and Drop
Local Storage
Web Workers
Server-Sent Events
Character Encoding
Text Formatting
Quotation and Citation Elements
Headings
Paragraphs
Links
Tables
Lists
Symbols
Space
Tab
Styles
Computer Code
Layout
Classes
Colors
Images
iframes
Audio Player
Video Player
YouTube Videos
Multimedia
Canvas
SVG
<!-- -->
<a>
<abbr>
<acronym> DEPRECATED
<address>
<applet> DEPRECATED
<article>
<aside>
<audio>
<b>
<base>
<basefont> DEPRECATED
<bdi>
<bdo>
<big> DEPRECATED
<blink> DEPRECATED
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center> DEPRECATED
<cite>
<code>
<col>
<colgroup>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir> DEPRECATED
<div>
<dl>
<dt>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font> DEPRECATED
<footer>
<form>
<frame> DEPRECATED
<frameset> DEPRECATED
<h1> – <h6>
<head>
<header>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<kbd>
<keygen> DEPRECATED
<label>
<legend>
<li>
<link>
<main>
<map>
<mark>
<menu>
<menuitem> DEPRECATED
<meta>
<meter>
<nav>
<noframes> DEPRECATED
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike> DEPRECATED
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt> DEPRECATED
<u>
<ul>
<var>
<video>
<wbr>