What is the <table> element in HTML?
The HTML <table> tag is used to show data in a tabular presentation in the form of rows and columns. A table consists of a table header, a table body, rows, and columns. There can be more than one column in a row. We can use the <table> element to generate a table to show data in tabular form, with the assistance of the <tr>, <td>, and <th> tags.
In every table:
- Table rows are designated by
<tr>tags. - The table header is designated by the
<th>tag. - Table data is designated by
<td>tags.
<tables>helps manage the layout of pages, such as the header section, footer section, navigation var, content, etc. However, it is good to use the<div>element instead of the table to manage the layout of the page.
Syntax
<table> //table tag
<head> // table header tag
<tr>
<th >Table_Header</th>
</tr>
</thead>
<body> // table body tag
<tr>
<td>Table_Body</td>
</tr>
</tbody>
</table>
Code
The following code demonstrates the usage of the <table> element in HTML. The table has three columns, F_Name (First Name), L_Name (Last Name), and Marks (lines 9-11). It also has four rows with the above-mentioned details (lines 14, 19, 24, and 29).