In HTML, a table is defined using the <table> element, which organizes data into rows and columns. It is structured with table rows (<tr>), table headers (<th>), and table data cells (<td>).
Basic Syntax
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
Key Table Elements
| Element | Purpose |
|---|---|
<table> |
Defines the table |
<tr> |
Table row |
<th> |
Table header cell (bold, centered) |
<td> |
Table data cell |
<thead> |
Groups table headers |
<tbody> |
Groups table body rows |
<tfoot> |
Groups table footer rows |
<caption> |
Provides a title for the table |
Example with <thead> and <tbody>
<table border="1">
<caption>Student Scores</caption>
<thead>
<tr>
<th>Name</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alice</td>
<td>85</td>
</tr>
<tr>
<td>Bob</td>
<td>92</td>
</tr>
</tbody>
</table>
border="1"→ adds a simple border (for demonstration)<caption>→ optional, gives a title to the table
💡 In Short:
Use
<table>along with<tr>,<th>, and<td>to create structured tabular data in HTML. Optional elements like<thead>,<tbody>, and<caption>help organize and label the table.