How to create a complex table in HTML

Coding HTML tables into your web page is fairly easy since you need only understand a few basic table codes.

The basic structure of an HTML table consists of the following tags:

Table tags: <table> </table>

Row tags: <tr> </tr>

Cell tags: <td> </td>

Constructing an HTML table consists of describing the table between the beginning table tag, <table>, and the ending table table tag, </table>. Between these tags, you then construct each row and each cell in the row. To do this, you would first start the row with the beginning row tag, <tr>, and then build the row by creating each cell with the beginning cell tag, <td>, adding the data for that cell, and then closing the cell with the ending cell tag, </td>. When you finish all of the cells for a row, you would then close the row with the ending row tag, </tr>.Then, for each new row, you would repeat the process of beginning the row, building each cell in the row, and closing the row.

Let's walk through an example by creating the following table:

In order to get started, first thing we need to do is to visualize the table in a full row-column version without any sliced rows or columns:

Now we can clearly see that we have a 5 rows x 5 columns table (25 total columns).

columns 4 and 5 are no longer needed since they are replaced by column 3 with colspan="3"

Combining Cells vertically

The next step to finish our table is to combine columns vertically according to the targeted table design that we saw in the first image. Do do this we need to combine columns (A5, B5, C5), (B2, C2) and (C1, D1).

For this, we're going to use the rowspan attribute. The rowspan attribute specifies the number of rows a cell should span (combine).