What is the <table> Element?
The <table> element is used to create tables in HTML. Tables are useful for displaying
structured data in rows and columns.
Hi, I'm Ahbab. In this article, I'll teach you how to create tables in HTML, including headers, rows, and cells, along with best practices for styling and organizing data.
The <table> element is used to create tables in HTML. Tables are useful for displaying
structured data in rows and columns.
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
<td>New York</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
<td>Los Angeles</td>
</tr>
</table>
This example demonstrates a simple table with headers and rows. The <th> element is used
for table headers, and the <td> element is used for table data.
border: Adds a border around the table.cellpadding: Adds padding inside table cells.cellspacing: Adds space between table cells.
<table style="border: 1px solid black; border-collapse: collapse;">
<tr>
<th style="border: 1px solid black; padding: 5px;">Name</th>
<th style="border: 1px solid black; padding: 5px;">Age</th>
<th style="border: 1px solid black; padding: 5px;">City</th>
</tr>
<tr>
<td style="border: 1px solid black; padding: 5px;">Alice</td>
<td style="border: 1px solid black; padding: 5px;">25</td>
<td style="border: 1px solid black; padding: 5px;">New York</td>
</tr>
<tr>
<td style="border: 1px solid black; padding: 5px;">Bob</td>
<td style="border: 1px solid black; padding: 5px;">30</td>
<td style="border: 1px solid black; padding: 5px;">Los Angeles</td>
</tr>
</table>
This example adds borders and padding to the table for better readability.
Which element is used for header cells in a table?