Tables in HTML
Creating Tables
Use the <table> tag to create tables. Inside a table, use:
• <tr> for table rows
• <td> for table data (cells)
• <th> for table headers
Basic Table Example
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
<td>24</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
</tr>
</table>
This will display:
Name Age
Alice 24
Bob 30
Adding Borders
By default, tables have no border. Use the border attribute to add one.
<table border="1">
...
</table>
Table Headings vs Data
• <th> is usually bold and centered.
• <td> is regular table data.
Spanning Columns and Rows
Use colspan and rowspan to merge cells.
Column Span Example:
<tr>
<th colspan="2">Employee Details</th>
</tr>
Row Span Example:
<tr>
<td rowspan="2">John</td>
<td>Manager</td>
</tr>
<tr>
<td>IT Department</td>
</tr>
Tip
• Keep your tables organized and easy to read.
• Use headers ( <th> ) for important rows or columns.
• Avoid very complex tables for layout—use CSS for page design.