Tutorialspoint.dev

HTML | th Tag

The <th> tag in HTML is used to set the header cell of a table. Two type of cell in HTML table.

  • Header Cell: It is used to hold the header information.
  • Standard Cell: It is used to hold the body of data.

The working of both tags (<th> and <td>) are same but the text properties are different. In <th> text is bold and centered, and in <td> text is regular and left align by default.

Syntax:

<th> Contents... </th>

Attributes: There are many attributes supported by HTML4.1 but removed from HTML5 are listed below:

  • abbr: This attribute is used as abbreviated version of the text content in a header cell.
  • align: Set the alignment the text content.
  • axis: Categorizes header cells.
  • bgcolor: Set the background color of a header cell.
  • char: Aligns the content in a header cell to a character.
  • charoff: It is used to sets the number of characters that will be aligned from the character specified by the char attribute. The value of this attributes are in numeric form.
  • colspan: Number of columns a header cell should span.
  • headers: Specifies one or more header cells a cell is related to.
  • height: Set the height of a header cell.
  • nowrap: It specifies that the content inside a header cell should not wrap.
  • rowspan: Set the number of rows a header cell should span.
  • scope: It is used to specify the score of header content.
  • sorted: It is used to sort the direction of a column.
  • valign It is used to set the vertically alignment of text content.
  • width: It is used to set the width of a header cell

Example:

<!DOCTYPE html>
<html>
    <head>
        <title>th tag</title>
        <style>
            body {
                text-align:center;
            }
            h1 {
                color:green;
            }
            th {
                color:blue;
            }
            table, tbody, td {
                border: 1px solid black;
                border-collapse: collapse;
            }
        </style>
    </head>
    <body>
        <center>
        <h1>GeeksforGeeks</h1>
        <h2>th Tag</h2>
        <table>
            <thead>
                <tr>
                    <!-- th tag starts here -->
                    <th>Name</th>
                    <th>User Id</th>
                    <!-- th tag end here -->
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Shashank</td>
                    <td>@shashankla</td>
                </tr>
                    <tr>
                    <td>GeeksforGeeks</td>
                    <td>@geeks</td>
                </tr>
            </tbody>
        </table>
        </center>
    </body>
</html>                                     

Output:

Supported Browsers: The browser supported by <th> tag are listed below:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera


This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter