×

HTML Nested Table

HTML nested table refers to a table that is created inside another table.

The table is in the form of rows and columns. From left to right are called horizontal rows, and from top to bottom are called vertical columns. Tables in HTML can be nested, meaning one table can be inserted into another table.

It is important to always place the inner table between the <td> … </td> of the outer table. We will create a table and try to nest the other table in the table and see the result.

We can create nested tables using <table> tag. The first table created is known as the outer table. The tables inside the outer tables are called nested tables.

Examples of HTML Nested Table

Example 1:

This example displays a table inside another table. We will create table A using HTML and nest another table B inside it. To identify and differentiate the two tables, we are setting the red border color of Table A and the yellow border color of Table B.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title> Example 1 of HTML Nested Table </title>
    </head>
<body>
	<table border="2" bordercolor="red">
		<tr>
			<td> Table <Adr></Adr> </td>
			<td> Table A
	<table border="2" bordercolor="yellow">
		<tr>
		       <td> Table B </td>
			<td> Table B </td>
		</tr>
		<tr>
			<td> Table B </td>
			<td> Table B </td>
		</tr>
	</table>
		</td>
		</tr>
		<tr>
			<td> Table A </td>
			<td> Table A </td>
		</tr>
	</table>
</body>
</html>

Output:

The output shows tables nested inside outer tables. We are adding nested tables inside the first row of the second column of the outer table. As you can see, table A has red border color, which is the outer table, and table B has yellow border color, which is the inner table. We have added border colours to differentiate the outer and inner tables easily.

HTML Nested Table

Example 2:

This example displays a nested table with some style, so we use HTML and CSS to create the nested table.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> Example 2 of HTML Nested Table </title>
</head>
<body>


    <table border="1" cellpadding="20px" bgcolor="black" cellspacing="5px" width="50%">


        <tr>
            <td bgcolor="purple"><h1> Column 6 </h1> </td>
            <td colspan="2" bgcolor="purple" >


             <table border="1" width="100%"  align="center" cellpadding="30px">
                 <tr>
                <td bgcolor="pink"></td>
                 <td bgcolor="pink"></td>
                 <td bgcolor="pink"></td> </tr>
             </table>


            </td>
        </tr>
        <tr>
            <td colspan="2" bgcolor="purple"><h1> Column 3 </h1></td>
            <td rowspan="2" bgcolor="purple">


        <table border="1" width="100%" align="center" cellpadding="30px">


            <tr> <td  bgcolor="pink" ></td> </tr>
            <tr> <td bgcolor="pink" ></td> </tr>
            <tr> <td bgcolor="pink" ></td> </tr>
            <tr> <td bgcolor="pink" ></td> </tr>
            <tr> <td bgcolor="pink" ></td> </tr>


        </table>


            </td>
        </tr>


        <tr>
            <td bgcolor="purple"> <h1>Column 5</h1> </td>
            <td bgcolor="purple"> <h1> Column 6 </h1> </td>
        </tr>
    </table>
    
</body>
</html>

Output:

The output shows a nested table designed with the help of CSS.

HTML Nested Table

Example 3:

In this example, we are creating a nested table inside another nested table. We will add inner table 2 inside the first row of the second column of outer table 1, and again we will add inner table 3 inside the first row of the second column of inner table 2.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title> Example 3 of HTML Nested Table </title>
    </head><body>
	<h2 style="color:pink"> HTML Nested Table </h2>


	<table border="2" bordercolor="pink">
		<tr>
			<td> Outer Table 1 row 1 col 1 </td>
			<td> Outer Table 1 row 2 col 1 
				<table border="2" bordercolor="blue">
					<tr>
						<td> Inner Table 2 row 1 col 1 
							<table border="2" bordercolor="red">
								<tr>
									<td> Inner Table 3 row 1 col 1 
									</td>
									<td> Inner Table 3 row 1 col 2 </td>
								</tr>
								<tr>
									<td> Inner Table 3 row 2 col 1 </td>
									<td> Inner Table 3 row 2 col 2 </td>
								</tr>
								<tr>
									<td> Inner Table 3 row 3 col 1 </td>
									<td> Inner Table 3 row 3 col 2 </td>
								</tr>
							</table>
						</td>
						<td> Inner Table 2 row 1 col 2</td>
					</tr>
					<tr>
						<td> Inner Table 2 row 2 col 1 </td>
						<td> Inner Table 2 row 2 col 2 </td>
					</tr>
					<tr>
						<td> Inner Table 2 row 3 col 1 </td>
						<td> Inner Table 2 row 3 col 2 </td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td> Outer Table row 2 col 1 </td>
			<td> Outer Table row 2 col 2 </td>
		</tr>
	</table>
</body>


</html>

Output:

The output shows the nested table inside the outer table and the other nested table inside the second nested table. As you can see, outer table 1 has a pink border, inner table 2 has a blue border, and inner table 3 has a red border. We can easily understand and identify the table with the help of different border colors.

HTML Nested Table

Browser Support:

It supports the following browsers:

  1. Google Chrome
  2. Internet Explorer
  3. Mozilla Firefox
  4. Safari
  5. Microsoft Edge
  6. Opera

Related Topics

How to Create a Portfolio Gallery using HTML and CSS?

First, before starting this, the user should know some of the basics of HTML and CSS to create a portfolio gallery. To add more functionality to the website, we can also...

7 minutes read.

HTML Reset Button

The HTML reset button is used to reset all values in the form. It clears all input fields. Reset is the value of the type attribute of the button element. The...

6 minutes read.

HTML Layouts

HTML Layouts HTML templates provide a way for well-managed, well-structured responsive web pages to be organized. We could say that the HTML layout specifies how web pages can be set up....

4 minutes read.

HTML Event Attributes

HTML Event Attributes If a browser responds to the user behavior, an event is called. For example, if we click on the submit button, a box of details will appear on...

4 minutes read.

Html Wbr Tag

The Line Break Opportunity element A word break opportunity is a place in text from where the browser breaks a line. This opportunity is represented by the element wbr in the...

2 minutes read.

How to change font in HTML

To give style to the content of your website, you may change the font of the text and make your website look attractive to the user. There are several methods which...

4 minutes read.

HTML Paragraphs

In html, there are some elements which starts with new line and one of them is paragraph. Which is said to be a block of text. In html <p> tag...

4 minutes read.

HTML Form Action

The <form> tag has an attribute named action that contains a URL. The HTML action attribute defines the webpage URL on which you want to send the data after submitting...

4 minutes read.

Responsive HTML5 and CSS3 Tutorial

Introduction to HTML5 Tutorial HTML5 is the latest and upgraded version of HTML. HTML is a hypertext markup language. Technically, it is not a programming language. It is a markup language. HTML...

17 minutes read.

HTML Links

It consist of anchor element which is used to create a link between a source anchor and destination anchor. The anchor tag can be embedded between text, image, video or...

2 minutes read.

CSS Clearfix

CSS Clearfix: A clearfix (or clear float) in CSS is for a component to clear or fix the child component, so we don’t need to insert additional markup. The clear...

4 minutes read.

How to append HTML code to a div using JavaScript?

In HTML, we have a div tag which is used to create a box where we can put a lot of other tags. So it works like a container. So,...

4 minutes read.

Design a tribute page using HTML and CSS

A tribute page is a webpage based on a person who inspired us in our life. In this article, we will create a webpage of Mahatma Gandhi. We are going...

5 minutes read.

HTML <script> Tag

For embedding a client -side script, we use script tag in html tag. This <script> tag can be used for containing scripting statements. It can also point another external script file...

2 minutes read.

HTML Button Disabled

The HTML <button> element has many attributes, one of them is the disabled attribute. The button on which you apply the disabled attribute will not work, or we can say...

4 minutes read.

HTML <br> tag

HTML is referred to as Hyper Text Markup Language, which is the most popular language for creating Web pages. HTML explains the construction of a Web page. It contains a...

4 minutes read.

HTML Charsets

In this tutorial, we are going to discuss about the charsets in the HTML. The letters, numbers, and several other symbols are shown correctly by the web browser. All of this...

2 minutes read.

HTML Unordered List

In HTML, we have <ul> tag which defines the unordered list. And it is also known as bulleted list, because as we know it is not ordered list therefore it...

2 minutes read.

HTML Background Image

Inserting image in HTML An image (technically digital image) in HTML or even in general technical aspects, is a binary representation of visual information. By visual information we mean, in the...

8 minutes read.

HTML <style> tag

The section of information that we want to style is contained in html style tag. It includes CSS, which is used to design the text and images in the web page. Syntax: <head> <title>…………....

3 minutes read.