HTML th tag

Last Updated on April 26, 2023 by Roshan Parihar


Definition of HTML th tag

HTML th tag is used in tables to show table header cells.

This tag is used in table header to display cells. We can use this tag in HTML thead tag. However, we can show table headings for each colums with this tag.



Syntax:

HTML th tag comes in the table rows to display header cells.

Output

Name Company Income(in $)
Galaxy S6 Samsung 200,000
Intex Aqua 4g Intex 10,000

Element Specific Attribute

Sr. No. Attribute Name Description
1 abbr
  • abbreviate the content in the table header.
  • The value for this is a abbreviated text
2 align
  • align the header cell content to the specified location.
  • The value for this can be:
    • left
    • right
    • center
    • justify
    • char
3 axis
  • The axis attribute used to specify the category of the table header cell.
  • the value for this can be name of the category.
4 bgcolor
  • A header cell background can be specified with the attribute.
  • the value for this can be:
    • name of color
    • A hexcode(eg #ccc)
    • color code in rgb formate e.g. (rgb(x, x, x))
5 char
  • the attribute is used only when the value of align attribute is char (align=”char”). When you want to specify the character in header to align, you can use this attribute.
  • Enter any character value for this.
6 charoff
  • Use this attribute in a table header cell only after you specify align=”char”. Defines an alignment offset against the first character with this attribute.
  • the value for this can be given in:
    • pixel (eg. 20px)
    • A percentage (eg. 8%)
7 colspan
  • colspan is used to specify the number of columns to merge.
  • the value for this can be a number
8 headers
  • specify the one or more header cell that contain information about a cell. This is a list of ids using id attribute of the cells
  • the value for this can be a id of the cell.
9 height
  • height of the header cell is given with this attribute
  • the value for this can be given in pixels.
10 nowrap
  • this prevents the automatic wrapping of the header cells.
  • the value for this is nowrap.
11 rowspan
  • rowspan is used to merge the rows of header cells.
  • the value for this is given by any numeric .
12 scope
  • The attribute can be used in header cells to specify the cells that uses the information of this header.
  • the value for this is given by:
    • row
    • rowgroup
    • col
    • colgroup
13 valign
  • this aligns text vertically in the specified location.
  • the value for this can be:
    • top
    • bottom
    • middle
    • baseline
14 width
  • Used to give the width of the header cell.
  • the value for this can be given in pixels or percentage(%).

Resources and References for HTML th tag

1. W3C Specification
2. HTML living standard
3. W3C project using Github