HTML <th> tag is used to define a header cell in a table. Header cells are typically display as bold and center text, and they help identify the content of the corresponding columns or rows in a table. The <th> tag can be used within <tr> elements in the context of <thead>, <tbody>, or <tfoot>.
HTML th tag
Allows for the use of attributes like scope, colspan, and rowspan to create more complex table layouts.
HTML th tag Key Points:
HTML <th> tag Attributes
scope: the header cell.
colspan: The number of columns a header cell should span.
rowspan: The number of rows a header cell should span.
HTML<th> Tag Example
<table border="1"> <thead> <tr> <th>Name</th> <th>Age</th> <th>Country</th> </tr> </thead> <tbody> <tr> <td>Abc</td> <td>30</td> <td>UK</td> </tr> <tr> <td>Xyz</td> <td>25</td> <td>US</td> </tr> </tbody> </table>
HTML <th> tag scope Attribute:
<table border="1"> <thead> <tr> <th scope="col">Name</th> <th scope="col">Age</th> <th scope="col">country</th> </tr> </thead> <tbody> <tr> <td>Abc</td> <td>30</td> <td>UK</td> </tr> <tr> <td>Xyz</td> <td>25</td> <td>US</td> </tr> </tbody> </table>