Nested HTML Tables

table in tableNested HTML tables are tables that are placed inside another table. They are used to create more complex and structured layouts with HTML tables. To create a nested table, you need to insert a <table> element inside a <td> element of the outer table.

How to Create Nested Tables Within HTML Tables?

Use the table generator and grab the HTML markup, then using an editor paste another table inside a cell.

<table style="background: AntiqueWhite">
  <tr>
    <td>A</td> <td>B</td>
  </tr>
  <tr>
    <td>C</td>
    <td>D
    <table style="background: white">
      <tr>
      <td>1</td> <td>2</td>
      </tr>
      <tr>
      <td>3</td> <td>4</td>
      </tr>
    </table>
  </td>
  </tr>
</table>
A B
C D
1 2
3 4

Nested 2×2 tables

We can place tables in the header and footer cells too.

<table style="background: Beige">
  <thead>
    <tr>
      <th>Head</th>
      <th>
        <table style="background: Lavender">
          <thead>
            <tr>
             <th>A</th><th>B</th>
            </tr>
          </thead>
          <tbody>
           <tr><td>C</td><td>D</td></tr>
         </tbody>
       </table>
      </th>
    </tr>
  </thead>
  <tbody>
    <tr><td>cell</td><td>cell</td></tr>
  </tbody>
</table>
Head
AB
CD
cellcell

An embedded table in a header cell.

Table In A Table In A Table

If you want to create a table inside a table inside a table, you can do so by nesting more elements inside the cell elements of the inner tables. We can combine as many tables as we wish.

🐧 🦐
🐼 🦁
B
C
1 2
3
😀 🤪
😦 😬

Use Colspan and Rowspan Instead

The colspan attribute is used to merge cells horizontally and rowspan is used to merge them downwards. Whenever possible, use them instead of nested tables to avoid complicating the code.

The same result with nested tables and rowspan & colspan

Hover the tables and click the pencil icons to inspect their source.

A B
1 2 3
4 5 6
D
E F
A B
1 2 3 D
4 5 6
E F

Using colspan and rowspan instead of nested tables can have some advantages, such as:

However, colspan and rowspan can also have some disadvantages, such as:

Therefore, you should use colspan and rowspan when you need to create simple and logical layouts, but avoid using them for complex and irregular layouts that might require nested tables

Nested Div Tables

We can place div tables inside other div tables. This is obvious because we can put <div> tags inside other divs. The online converter at DivTable.com supports converting nested tables to structured divs.

<div class="divTable" style="background: AntiqueWhite">
  <div class="divTableBody">
    <div class="divTableRow">
      <div class="divTableCell">A</div>
      <div class="divTableCell">B</div>
    </div>
    <div class="divTableRow">
      <div class="divTableCell" style="padding:0">
        <div class="divTable" style="background: Beige">
          <div class="divTableBody">
            <div class="divTableRow">
              <div class="divTableCell">1</div>
              <div class="divTableCell">2</div>
              <div class="divTableCell">3</div>
            </div>
            <div class="divTableRow">
              <div class="divTableCell">4</div>
              <div class="divTableCell">5</div>
              <div class="divTableCell">6</div>
            </div>
          </div>
        </div>
      </div>
      <div class="divTableCell">D</div>
    </div>
    <div class="divTableRow">
      <div class="divTableCell">E</div>
      <div class="divTableCell">F</div>
    </div>
  </div>
</div>
A
B
1
2
3
4
5
6
D
E
F

Nested HTML Table Generator

The online generator helps you create the code for HTML tables. Then you can easily place them inside each other, using any text editor.

2 × 2

Table

Style Name
Georgia
Georgia
Palatino
Times New Roman
Arial
Arial Black
Comic Sans
Impact
Lucida Sans
Tahoma
Trebuchet
Verdana
Courier
Lucida Console
Left Center Right
px
px

Body

Left Center Right

HTML
Preview Apply »
HTML Copy
CSS « Apply