Menu

Rowspan and Colspan

Rowspan and Colspan

Sometimes a table cell needs to stretch across multiple rows or columns, like a header that spans two columns. The attributes rowspan and colspan handle this.

colspan makes a cell span horizontally across multiple columns. rowspan makes a cell span vertically across multiple rows.

<table>

  <tr>

    <th colspan="2">Contact Info</th>

  </tr>

  <tr>

    <td>Email</td>

    <td>Phone</td>

  </tr>

</table>

Explanation:

  • Here, colspan= "2" makes the header cell stretch across both columns below it, instead of sitting above only one.
  • When you use colspan or rowspan, remember to remove the extra td tags that would have filled that space, or your table will misalign.

HTML Tutorial (From Basics to Implementation)

AP

Abhishek Pati





Get in Touch For Details