Performance: Table structure
Table structure affects page load speed and rendering performance by influencing DOM size and layout complexity.
<table><thead><tr><th>Item</th><th>Detail</th></tr></thead><tbody><tr><td>Item 1</td><td>Detail 1</td></tr><tr><td>Item 2</td><td>Detail 2</td></tr></tbody></table>
<table><tr><td>Item 1</td><td>Detail 1</td></tr><tr><td>Item 2</td><td>Detail 2</td></tr></table>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Non-semantic table | Moderate DOM nodes | Multiple reflows per row | Higher paint cost due to layout complexity | [X] Bad |
| Semantic table with <thead>, <tbody>, <th> | Moderate DOM nodes | Single reflow after layout | Lower paint cost with optimized layout | [OK] Good |
<tr> tag defines a row in an HTML table.<td> and <th> define cells, not rows.<thead> tag defines the header section of a table.<tbody> is for body rows, <tfoot> for footer, and <th> is a cell tag.<table> <tr><th>Name</th><th>Age</th></tr> <tr><td>Alice</td><td>30</td></tr> </table>
<tr> has two <th> cells: 'Name' and 'Age', creating two columns.<tr> has two <td> cells: 'Alice' and '30', filling the columns.<table> <tr><td>Item</td><td>Price</td></tr> <td>Book</td><td>$10</td> </table>
<td>Book</td><td>$10</td> are not wrapped inside a <tr> tag, which is required.<tr>. Missing it causes invalid structure.<caption> tag must be directly inside <table>, before <thead>.<thead> contains header row with <th>, <tbody> has two data rows, and <tfoot> has footer row.<th>, not <td>.Pass the test and this pattern moves unknown