Performance: Table headers
Using proper table headers affects page accessibility and rendering stability, impacting visual stability and user experience.
<table> <thead> <tr> <th scope="col">Name</th> <th scope="col">Age</th> </tr> </thead> <tbody> <tr> <td>Alice</td> <td>30</td> </tr> </tbody> </table>
<table> <tr> <td>Name</td> <td>Age</td> </tr> <tr> <td>Alice</td> <td>30</td> </tr> </table>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using <td> for headers | Minimal DOM nodes | Multiple reflows if styles change | Higher paint cost due to layout shifts | [X] Bad |
| Using <th> with scope | Minimal DOM nodes | Single reflow with stable layout | Lower paint cost with stable header rendering | [OK] Good |
<th> tag in an HTML table?<th><th> tag is used to create header cells in a table, which label columns or rows.<td> tag creates normal data cells, not headers. Captions use <caption>, and merging cells uses colspan or rowspan.<th>.<td> is for data cells, <header> is a page section tag, and <thead> groups header rows but does not create individual cells.<th> elements in most browsers?<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Alice</td>
<td>30</td>
</tr>
</tbody>
</table><th> cells with bold text and center alignment to distinguish headers.<td>) are usually normal weight and left-aligned by default.<table>
<thead>
<tr>
<th>Product</td>
<th>Price</th>
</tr>
</thead>
</table><th> but incorrectly closes with </td>, which is invalid.<thead> and <tr> tags are correctly used and closed. The second header cell uses <th> correctly.<th> tags to indicate headers.<th> in the top row and first column. The empty <th> in the top-left corner aligns headers properly.Pass the test and this pattern moves unknown