HTML tables are used to present data in a tabular format. Tables are defined with the <table>
element, and table rows are defined with the <tr>
element. Table cells are defined with the <td>
element (for data cells) or the <th>
element (for table headers).
Here is an example of a simple HTML table:
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
<tr>
<td>Alice</td>
<td>alice@example.com</td>
<td>555-555-1212</td>
</tr>
<tr>
<td>Bob</td>
<td>bob@example.com</td>
<td>555-555-1213</td>
</tr>
</table>
This will create a table with three columns (Name, Email, and Phone) and two rows of data.
You can also use the <thead>
, <tbody>
, and <tfoot>
elements to group rows within the table. The <thead>
element is used to define a set of rows that make up the table header, the <tbody>
element is used to define the main content of the table, and the <tfoot>
element is used to define a set of rows that make up the table footer.
Here is an example of a table using these elements:
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alice</td>
<td>alice@example.com</td>
<td>555-555-1212</td>
</tr>
<tr>
<td>Bob</td>
<td>bob@example.com</td>
<td>555-555-1213</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">Total: 2</td>
</tr>
</tfoot>
</table>
0 Comments