Table
A table organizes data into a grid of rows and columns.
In HTML, you can create a table on a web page using the <table>
tag.
Basic Structure
The main tags used to create a table are as follows:
-
<table>
: Creates the table element -
<tr>
: Defines a row in the table. It stands for "table row". -
<td>
: Defines a cell in the table that contains data. It stands for "table data". -
<th>
: Defines a header cell in the table. It is usually rendered in bold text.
Example
Here is a simple table example.
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>Occupation</th>
</tr>
<tr>
<td>John</td>
<td>25</td>
<td>Developer</td>
</tr>
<tr>
<td>Jane</td>
<td>28</td>
<td>Designer</td>
</tr>
</table>
The example above creates a 3x3 table where the first row is composed of header cells, and the remaining rows are composed of data cells.
Other Table-Related Tags
There are also tags to make the table structure more refined.
-
<thead>
: Groups the header content in the table -
<tbody>
: Groups the body content in the table -
<tfoot>
: Groups the footer content in the table
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.