Introduction
The <table>
element in HTML is used to create a table of data. Tables are composed of rows (<tr>
) and cells (<td>
or <th>
), where <td>
represents standard data cells and <th>
represents header cells.
Here’s a basic example of how you might use the <table>
element:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table border="2">
<tr>
<td>Id</td>
<td>Name</td>
<td>Mobile</td>
<td>Desig</td>
<td>City</td>
</tr>
<tr>
<td>101</td>
<td>Manish</td>
<td>890xxxxxxx</td>
<td>Developer</td>
<td>Rewari</td>
</tr>
<tr>
<td>102</td>
<td>Rohit</td>
<td>890xxxxxxx</td>
<td>Web Designer</td>
<td>Rewari</td>
</tr>
</table>
</body>
</html>
Output:
In this example:
- The
<table>
element defines the table. - Each row of the table is defined by the
<tr>
(table row) element. - Within each row, data cells are represented by the
<td>
(table data) element.
This results in a simple table with five columns: Id, Name, Mobile, desig and City, and two rows of data.