Th tag in HTML5

in this article I am going to describe about the Th tag in HTML5.
  • 1495

Th Tag in HTML5

<th> tag is used for defining the table headers of cells or columns in a table. The <th> tag is used within the <tr> tag and <tr> is nested in <table> tag. This tag must have opening and closing tags. Table header cell means its contain information about header.

An HTML table has two kinds of cells:

  1. Header cells - contains header information (created with the <th> element)
  2. Standard cells - contains data (created with <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

It is supported in all major browsers.

Syntax

<th>Column header</th>

Attributes

    Attribute     Value     Description
   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

Some HTML 4.01 attributes are not supported in HTML5.

Attributes not supported by HTML5 are

  • abbr
  • align
  • axis
  • bgcolor
  • char
  • charoff
  • height
  • nowrap
  • valign
  • width

Example of <th> tag in HTML5

<!DOCTYPE html>

 

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>

    <meta charset="utf-8" />

    <title>Th tag in HTML5</title>

    <table border="1">

        <tr>

            <th>Employee id</th>

            <th>Employee Name</th>

            <th>Salary</th>

            <tr>

                <td>10</td>

                <td>Ashwani</td>

                <td>10000</td>

            </tr>

            <tr>

                <td>11</td>

                <td>Anubhav</td>

                <td>12000</td>

            </tr>

    </table>

</head>

<body>

    <p>Table Header Tag in HTML5</p>

</body>

</html>

Output

th.jpg

© 2020 DotNetHeaven. All rights reserved.