The <table> tag is used to begin a table. Within a table element
are the <tr> (table rows) and <td> (table columns) tags.
There are three tags/elements in table.
1. <tr> - table row
2. <td> - table data/column
3. <th> - table heading
Create Simple Table with 2 Rows and 2 Columns using tr and td tags.
HTML Code:
<table border="1">
<tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr>
<tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr>
</table>
Output:
Row 1 Cell 1
Row 1 Cell 2
Row 2 Cell 1
Row 2 Cell 2
Now we create another table using tr and th tags.
<table border="1">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td>Row 2 Cell 1</td>
<td>Row 2 Cell 2</td>
<td>Row 2 Cell 3</td>
</tr>
</table>
Output:
Column 1
Column 2
Column 3
Row 2 Cell 1
Row 2 Cell 2
Row 2 Cell 3
Spanning Multiple Rows and Columns
Use colspan to span multiple columns.
HTML Code:
<table border="1">
<td>Row 1 Cell 2</td><td>Row 1 Cell 3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>
Output: