Performance: Table rows and columns
This affects page load speed and rendering performance by increasing DOM size and layout complexity when many table rows and columns are used.
<table> <thead> <tr><th>Item</th><th>Detail</th><th>Extra</th></tr> </thead> <tbody> <!-- Render only visible rows with pagination or virtual scrolling --> </tbody> </table>
<table> <tr><td>Item 1</td><td>Detail 1</td><td>Extra 1</td></tr> <!-- Repeat hundreds of rows --> </table>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large table with 1000+ rows and many columns | Very high (1000+ rows) | Hundreds of reflows | High paint cost | [X] Bad |
| Table with pagination showing 20 rows at a time | Low (20 rows) | Single reflow per page | Low paint cost | [OK] Good |
| Table with virtual scrolling rendering visible rows only | Minimal DOM nodes | Minimal reflows | Minimal paint cost | [OK] Good |
<tr> tag defines a table row, while <td> and <th> define cells inside rows.<th> tags to label columns or rows.<th>Header</th> uses <th> correctly for a header cell.<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
<td>30</td>
</tr>
</table><th> for headers 'Name' and 'Age'. The second row uses <td> for data 'Alice' and '30'.<table>
<tr>
<td>Item 1</td>
<tr>
<td>Item 2</td>
</tr>
</table><tr> is opened but not closed before the second <tr> starts.<tr> must have a matching closing </tr>. Here, the first row is missing its closing tag.<th> tags for all three headers to label columns.<table>
<tr>
<th>Product</th>
<th>Price</th>
<th>Stock</th>
</tr>
</table> correctly uses <th> inside a <tr> for all headers. <table>
<tr>
<td>Product</td>
<td>Price</td>
<td>Stock</td>
</tr>
</table> uses <td> which is for data cells, not headers. <table> <th>Product</th> <th>Price</th> <th>Stock</th> </table>places
<th> directly inside <table> without a row. <table>
<tr>
<th>Product</th>
<td>Price</td>
<td>Stock</td>
</tr>
</table> mixes <th> and <td> in the header row, which is incorrect.Pass the test and this pattern moves unknown