×

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

HTML Hide Element

The HTML hide element is used to hide the element. We place the hidden attribute inside those elements which we want to hide. The hidden attribute is a Boolean attribute. The...

3 minutes read.

HTML 5 Tutorial

What is HTML5? HTML5 is a programming language which stands for the acronym Hyper Text Markup Language 5. It is program that enables the appearance of web pages to be changed, as well as changes...

5 minutes read.

How to create a link with no underline in HTML

In HTML, an anchor tag (<a>) is a Styled Container tag, which means when a hyperlink is created using this, browsers, by default, display the link by applying some styles...

5 minutes read.

HTML Audio

HTML AUDIO: HTML5 provides a method to embed the audio file into a webpage by using HTML5. Before HTML5 audio files is used to play on the browser with the help of...

1 minute read.

HTML <select> tag

This tag helps in making the drop-down list on the web page. This is highly used in HTML forms for taking the input from user. You can use the id attribute...

3 minutes read.

HTML SVG

HTML SVG: SVG stands for Scalable Vector Graphics which defines the graphics for the web. It is a language for describing 2-D graphics in XML. Each drawn shape in SVG is...

1 minute read.

HTML Ordered List

We use <ol> tag to make an ordered list in html. An ordered list is made to make a list of items in ordered form, ordered list can be either...

3 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.

Most Commonly used Tags in HTML

In this tutorial, we'll look at the most popular HTML tags. We know HTML is a fundamental requirement for creating a website. As a result, it is essential to remember...

9 minutes read.

HTML Lists

HTML List HTML lists are used to specify data sets. All lists can include one or more elements from the list. HTML lists are available in three different types: Ordered List or...

4 minutes read.

HTML <section> tag

The section element in HTML is used to define sections in a document. Syntax of Section Tag: <body> <h1>……….</h1> <section> <h2>……….</h2> <p> …………………………</p> </section> <section> <h2>………..</h2> <p>…………………………. <p> </section> </body> Examples of Section Tag Example 1: In this example, we use the HTML "section" element...

3 minutes read.

HTML Images

HTML has <img> tag to display image on the web pages or web application. This tag is an empty tag i.e. we don't have to close this tag while using. SYNTAX: <img src="source address" attributes="alt, height, width"> Example: <html>   <body>   <center>Image tag Example</center>   <img src="https://www.tutorialandexample.com/resources/images/favicon.png"    alt="tutorialandexample"/>   </body>   </html> Output: Image...

1 minute 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.

HTML5 Tags

HTML5 Tags A list of newly included tags is provided in HTML5. These HTML 5 tags (elements) provide a better structure for the document. This list shows description of all HTML...

3 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 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 Attributes

HTML Attributes provide the additional information about HTML elements. Attributes are always specified in the start tag. Attributes usually comes in pairs. lang Attribute This attribute helps in declaring the language...

2 minutes read.

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 City tag

HTML <City> tag HTML < cite > tag specifies a citation, a reference or title to a creative work, quoted content, books, websites, a research paper, a blog post, a painting,...

3 minutes read.