Introduction to HTML Tables
To use any data in a structured form you'll use table. By including tables in your webpage you can make it more structured and creative. To create tables in HTML you use <table> tag. There is a sub tag of this <table> tag which is known as <tr> table row tag. <tr> tag also has its sub tag which is called <td> table data tag.
Creating Tables in HTML
Any table is made by row and columns. So after <table> tag for creating row you use <tr> tag. The more you want to create rows the more you have to define <tr> tag. After creating rows columns were created in rows. The more you want create columns the more have to define <td> tag.
The example has been given below:
<html> <head><title>table web page</title> </head> <body> <table border="1"> <tr> <td>First row first column</td> <td>First row second column</td> </tr> <tr> <td>Second row First column</td> <td>Second row Second column</td> </tr> </table> </body> </html> |
First row first column | First row second column |
Second row First column | Second row Second column |
One more thing you have remember when you'll not define the value of table by border attribute then table border will not show.
Creating Table Headings
<html> <head><title>Table Heading Tag</title> <.head> <body> <table border="1"> <tr> <th>Name</th> <th>Address</th> </tr> <tr> <td> Gaurav Rai </td> <td>India</td> </tr> </table> </body> </html> |
Name | Address |
---|---|
Gaurav Rai | India |
Colspan Atttribute
<html> <head><title>colspan attribute</title> </head> <body> <table border="1"> <tr> <th>Name</th> <th colspan="2"> Mobile No. </th> </tr> <tr> <td>Gaurav</td> <td>9540168751</td> <td>8506091548</td> </tr> <tr> <td>Prarreek</td> <td>8587078127</td> </tr> </table> </body> </html> |
Name | Mobile No. | |
---|---|---|
Gaurav | 9540168751 | 8506091548 |
Prarreek | 8587078127 |
Rowspan Attribute
<html> <head><title>Rowspan Attribute</title> </head> <body> <table border="1"> <tr> <th rowspan="2">Colors</th> <td>Red</td> <tr> <td>Lime</td> </tr> <tr> <th rowspan="2">Fruits</th> <td>Guava</td></tr> <tr> <td>Apple</td> </tr> </table> </body> </html> |
Colors | Red |
---|---|
Lime | |
Fruits | Guava |
Apple |
Naming The Table
<html> <head><title>Naming the Table</title> </head> <body> <table border="1"> <caption>Table Name</caption> <tr> <td>Gaurav Rai</td> <td>India</td> </tr> </table> </body> </html> |
Gaurav Rai | India |