HTML Tables
A guide to understanding how to use tables in HTML, including table rows, headers, cells, and advanced features like colspan and rowspan.
📊 In this guide, we will explore key HTML table elements, their structure, and advanced features like colspan, rowspan, and table styling.
HTML tables are used to display data in a structured way using rows and columns. Here's how you can create and style tables in HTML:
📋 Basic Table Structure
The basic structure of an HTML table involves the following tags:
- 🗂️
<table>: This is the container for the table. - 🏷️
<tr>: Defines a table row. - 🏷️
<th>: Represents a table header cell (usually bold and centered). - 🏷️
<td>: Represents a table data cell (where content is displayed).
🛠️ Example:
➕ colspan and rowspan
You can merge table cells using colspan and rowspan attributes.
- ➡️
colspan: Spans a cell across multiple columns. - ⬇️
rowspan: Spans a cell across multiple rows.
🛠️ Example:
🗂️ Table Sections: <thead>, <tbody>, <tfoot>
HTML5 introduced sections to structure tables for better readability and accessibility:
- 🏷️
<thead>: Contains the header row. - 🏷️
<tbody>: Contains the main data rows. - 🏷️
<tfoot>: Contains the footer row (often for totals or summaries).
🛠️ Example:
🎨 Table Borders and Styling
By default, HTML tables are plain. You can style them using CSS.
🛠️ Example:
🧪 Try Yourself
✅ Conclusion
HTML tables are a powerful way to display structured data on webpages. By using basic elements like <table>, <tr>, <th>, and <td>, along with colspan and rowspan, you can build complex, readable tables.
💡 Pro Tip: Always use <thead>, <tbody>, and <tfoot> for better table structure and accessibility.