HTML Tables
Master HTML tables and organize data effectively. Learn table structure, rows, columns, headers, styling, and best practices for displaying tabular data.
- What are Tables?
- Table Structure
- Table Tags
- Headers & Structure
- Borders & Styling
- colspan & rowspan
- Best Practices
- Try It Yourself
- Summary
- FAQ
What are HTML Tables?
An HTML table organizes data into rows and columns, making it easy to display structured information — products, prices, schedules, comparisons, and more.
Table Structure
An HTML table consists of rows and columns. Each intersection is a cell. Here's a live example:
| Course | Price | Lessons | Status |
|---|---|---|---|
| HTML Fundamentals | Free | 22 | Available |
| CSS Mastery | Free | 20 | Available |
| JavaScript Pro | Free | 25 | Coming Soon |
Table Tags
<table> <tr> <td>Cell 1</td> <td>Cell 2</td> </tr> <tr> <td>Cell 3</td> <td>Cell 4</td> </tr> </table>
<table> — Table Container
Wraps all table content. A block-level element that creates the grid structure.
<tr> — Table Row
Defines a horizontal row. Contains <td> or <th> cells.
<td> — Table Data Cell
A regular data cell — where your actual data goes.
<th> — Table Header Cell
Header cell — bold and center-aligned by default. Improves accessibility and SEO.
Table Headers & Semantic Structure
Use <thead>, <tbody>, and <tfoot> for proper semantic organization:
<table> <thead> <tr> <th>Name</th> <th>Email</th> <th>Role</th> </tr> </thead> <tbody> <tr> <td>Sarah Jones</td> <td>sarah@tipsinlearning.com</td> <td>Designer</td> </tr> </tbody> <tfoot> <tr> <td colspan="3">Total: 1 member</td> </tr> </tfoot> </table>
Borders and Styling
table { width: 100%; border-collapse: collapse; } th, td { padding: 12px; border: 1px solid #e2e8f0; text-align: left; } th { background: linear-gradient(135deg, #e85d04, #7c3aed); color: white; font-weight: 700; } tr:hover td { background-color: rgba(232, 93, 4, 0.05); } /* Alternating row colors */ tbody tr:nth-child(even) td { background: rgba(124, 58, 237, 0.03); }
Advanced — colspan & rowspan
Merge cells horizontally with colspan and vertically with rowspan:
<!-- colspan: span 2 columns --> <tr> <th colspan="2">Q4 Sales Report</th> </tr> <!-- rowspan: span 2 rows --> <tr> <td rowspan="2">Category</td> <td>January Sales</td> </tr>
Best Practices
Accessibility
- Use <th scope="col"> for column headers
- Add <caption> to describe the table's purpose
- Keep tables focused on one data set — avoid nesting
Try It Yourself
Questions Beginners Ask
Common questions about HTML tables: