Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
HTML table attributes allow you to control how cells span across rows and columns, and how content is aligned within cells. Common attributes include colspan,rowspan, andalign.
Merge cells horizontally across columns
<td colspan="2">Spans 2 columns</td>Merge cells vertically across rows
<td rowspan="2">Spans 2 rows</td>Align content (left, center, right)
<td align="center">Centered</td>Set column width (use CSS instead)
<td width="200">Wide cell</td>Combines multiple columns into one cell
<td colspan="3">
Spans 3 columns
</td>Combines multiple rows into one cell
<td rowspan="2">
Spans 2 rows
</td>Using colspan and rowspan for complex tables
<h3>Schedule with Merged Cells</h3>
<table>
<thead>
<tr>
<th>Time</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
</tr>
</thead>
<tbody>
<tr>
<td>9:00 AM</td>
<td colspan="2">Team Meeting</td>
<td>Workshop</td>
</tr>
<tr>
<td>1:00 PM</td>
<td rowspan="2">Project Work</td>
<td>Review</td>
<td rowspan="2">Training</td>
</tr>
<tr>
<td>3:00 PM</td>
<td>Lunch Break</td>
</tr>
</tbody>
</table>Loading preview...
Borders merge into single lines
table {
border-collapse: collapse;
}Space between cell borders
table {
border-collapse: separate;
border-spacing: 8px;
}Compare border-collapse and border-spacing
<h3>Tables with Different Spacing</h3>
<div class="table-wrapper">
<h4>Border Collapse</h4>
<table class="collapse-table">
<tr>
<th>Name</th>
<th>Score</th>
</tr>
<tr>
<td>Alice</td>
<td>95</td>
</tr>
<tr>
<td>Bob</td>
<td>87</td>
</tr>
</table>
</div>
<div class="table-wrapper">
<h4>Border Separate</h4>
<table class="separate-table">
<tr>
<th>Name</th>
<th>Score</th>
</tr>
<tr>
<td>Alice</td>
<td>95</td>
</tr>
<tr>
<td>Bob</td>
<td>87</td>
</tr>
</table>
</div>Loading preview...
While HTML align attribute still works, it's better to use CSS text-align and vertical-align properties for modern websites.
Aligning content in table cells
<h3>Table with Data Attributes</h3>
<table>
<thead>
<tr>
<th>Product</th>
<th data-type="number">Price</th>
<th data-type="number">Quantity</th>
<th data-type="number">Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Laptop</td>
<td align="right">$999</td>
<td align="center">2</td>
<td align="right">$1998</td>
</tr>
<tr>
<td>Mouse</td>
<td align="right">$25</td>
<td align="center">5</td>
<td align="right">$125</td>
</tr>
<tr>
<td>Keyboard</td>
<td align="right">$75</td>
<td align="center">3</td>
<td align="right">$225</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Totals</th>
<td colspan="2" align="right">10 items</td>
<td align="right">$2348</td>
</tr>
</tfoot>
</table>Loading preview...