Problem Statement
Which tag is used to define header cells in a table?
Explanation
The th tag is used to define header cells in a table. The th stands for table header. Header cells are typically used in the first row or first column to label what each column or row represents. By default, content in th cells is bold and center-aligned, making headers stand out visually. More importantly, th tags have semantic meaning. Screen readers use th tags to help visually impaired users understand table structure and navigate data. You can use the scope attribute with th tags to explicitly specify whether the header is for a column or row. This improves accessibility. Using th instead of td for headers is a best practice that makes your tables more semantic and accessible.
Code Solution
SolutionRead Only
<!-- Table with header row -->
<table>
<tr>
<th>Product</th>
<th>Price</th>
<th>Stock</th>
</tr>
<tr>
<td>Laptop</td>
<td>$999</td>
<td>15</td>
</tr>
<tr>
<td>Mouse</td>
<td>$25</td>
<td>50</td>
</tr>
</table>