How to combine or merge cells in an HTML table

Updated: 04/02/2019 by Computer Hope
merge cells with html

You can merge two or more table cells together by using the colspan attribute in a <td> HTML tag (table data). For example, in the below code is a table with three rows and three columns.

If we wanted to combine the first two cells into one cell, we could use the colspan="2" attribute in the first <td> tag. The number represents how many cells you want to use for the <td> tag.

Example HTML table

<table>
 <tr>
  <td colspan="2">&nbsp;</td>
  <td>&nbsp;</td>
 </tr>
 <tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
 </tr>
 <tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
 </tr>
</table>

The above code, rendered in a web browser, produces a table similar to the table shown below. As you can see, the first cell spans the width of two columns.

   
     
     

To use all three cells on the top of the table, increase the colspan value to 3 since there are three columns. Increasing the value to 3 gives you a table similar to the example shown below.

 
     
     
Note

Make sure that when you expand a <td> column that you remove any remaining <td> tag. In the example above, because we are using all three columns, we have only one <td> in the <tr> (table row).

Merging cells using a WYSIWYG editor

You can also use the WYSIWYG editor to merge cells. To merge a cell in a WYSIWYG editor highlight two or more cells, right-clicking the cells and then choosing the option to merge cells. Below is additional steps on how to do this in Dreamweaver and Expression Web.

Merging cells using Dreamweaver

  1. Highlight two or more cells in your table.
  2. Right-click on the highlighted cells.
  3. Click Table and then Merge Cells.

or

  1. Highlight two or more cells in your table.
  2. Press the keyboard shortcut Alt+Ctrl+M.

Merging cells using Expression Web

  1. Highlight two or more cells in your table.
  2. Right-click on the highlighted cells.
  3. Click Modify and then Merge Cells.

Additional information