HTML tables are used to organize and display data in a tabular format on web pages. They are created using a combination of HTML tags to define the structure and content of the table. Here’s a brief overview of the main elements used to create HTML tables:
<table>
: This tag defines the beginning and end of the table.
<tr>
: This tag defines a table row.
<th>
: This tag defines a table header cell, which is typically bold and centered.
<td>
: This tag defines a table data cell.
Here is a simple example of an HTML table:
<table border="1">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>Taylor</td>
<td>35</td>
</tr>
<tr>
<td>Tom</td>
<td>Taylor</td>
<td>30</td>
</tr>
</table>
In this example:
The <table border="1">
element creates a table with a border.
The <tr>
elements define rows in the table.
The first row uses <th>
elements for headers: “First Name,” “Last Name,” and “Age.”
Subsequent rows use <td>
elements for data cells, such as “John,” “Taylor,” and “35.”