Merging Cells

Merging cells in HTML tables means combining two or more cells into a single cell. This is used to make tables more organized and to display data in a better layout.

What is Cell Merging

Cell merging allows you to join multiple rows or columns into one cell. It is useful when you want to create headings or group related data.

Colspan Attribute

The colspan attribute is used to merge columns. It combines cells horizontally.

Example of Colspan

<table> <tr> <th colspan=”2″>Student Information</th> </tr> <tr> <td>Name</td> <td>Age</td> </tr> </table>

Rowspan Attribute

The rowspan attribute is used to merge rows. It combines cells vertically.

Example of Rowspan

<table> <tr> <td rowspan=”2″>Ali</td> <td>Math</td> </tr> <tr> <td>English</td> </tr> </table>

When to Use Merging Cells

Use colspan when you want to combine columns under one heading.
Use rowspan when you want to combine rows for the same data.

Benefits of Merging Cells

It improves table design and makes data easier to read. It also helps in creating professional layouts for reports and data presentation.

Summary

Merging cells in HTML tables is done using colspan and rowspan attributes. It helps combine multiple rows or columns into a single cell for better structure and readability.

Home ยป HTML Intermediate > Tables & Data Representation > Merging Cells