HTML Tables
Learn how to create HTML tables using table, tr, th, and td tags with clear examples and best practices.
HTML tables are used to display data in rows and columns.
They are best suited for tabular data, not layout.
Basic Table Structure
<table>
<tr>
<th>Course</th>
<th>Duration</th>
</tr>
<tr>
<td>HTML</td>
<td>2 Weeks</td>
</tr>
</table>
Table with Common Attributes
<table border="1" cellpadding="10" cellspacing="0">
<caption>Course Details</caption>
<thead>
<tr>
<th scope="col">Course</th>
<th scope="col">Duration</th>
</tr>
</thead>
<tbody>
<tr>
<td>HTML</td>
<td>2 Weeks</td>
</tr>
</tbody>
</table>
Attributes Used
border→ table bordercellpadding→ cell spacingcellspacing→ space between cellsscope→ header relation
Table Tags Explained
<table>→ table container<tr>→ table row<th>→ header cell<td>→ data cell<caption>→ table title
Important Notes
- Use tables only for data
- Avoid tables for page layout
- Use
<th>for headers - CSS is preferred for styling tables
Was this helpful?
Thanks for your feedback!