Performance: Cell merging
Cell merging affects layout calculation and painting performance because it changes how table cells span multiple rows or columns.
<table> <thead> <tr><th colspan="2">Merged Header</th></tr> </thead> <tbody> <tr><td>Data 1</td><td>Data 2</td></tr> <tr><td>Data 3</td><td>Data 4</td></tr> </tbody> </table>
<table> <tr> <td rowspan="10">Merged Cell</td> <td>Data 1</td> </tr> <tr> <td>Data 2</td> </tr> <!-- many more rows --> </table>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large rowspan/colspan in many rows | Moderate DOM nodes | Multiple reflows proportional to span | High paint cost due to complex layout | [X] Bad |
| Merged headers with colspan | Fewer DOM nodes | Single reflow for header | Lower paint cost | [OK] Good |
colspan attribute do in an HTML table?colspancolspan attribute is used in a table cell to make it span across multiple columns horizontally.rowspanrowspan merges cells vertically across rows, so it is different from colspan.colspan = horizontal merge [OK]colspan, so it should be used as colspan='2'.<td colspan='2'>Merged</td> uses the correct attribute and syntax: <td colspan='2'>Merged</td>. Other options use wrong attributes or invalid syntax.<table border='1'>
<tr>
<td rowspan='2'>A</td>
<td>B</td>
</tr>
<tr>
<td>C</td>
</tr>
</table>rowspan='2' on cell 'A' makes it cover two rows vertically in the first column.<table border='1'>
<tr>
<td colspan='2'>Merged</td>
<td>Cell 3</td>
</tr>
<tr>
<td>Cell 4</td>
<td>Cell 5</td>
</tr>
</table>colspan='2' plus one more cell, so total columns = 2 + 1 = 3.rowspan='2' and colspan='3' are needed.<td rowspan='2' colspan='3'>Top Left</td> correctly uses rowspan='2' and colspan='3'. Other options have swapped or incorrect values.Pass the test and this pattern moves unknown