HTML Table Tag Explained with Examples for Beginners

Learn the HTML table tag with practical examples. Understand table, tr, th, td, thead, tbody, tfoot, colspan, rowspan, responsive tables, and modern table best practices.
HTML Table Tag Explained with Examples
The HTML <table> tag is used to display structured data in rows and columns.
Tables are commonly used in:
- admin dashboards
- analytics systems
- financial reports
- pricing tables
- product listings
- student records
- order management systems
Understanding HTML tables is important because data presentation is a major part of frontend development.
What is the HTML Table Tag?
The <table> tag creates a table structure.
Basic example:
<table>
</table>
However, a proper table contains additional tags like:
-
<tr> -
<th> -
<td>
These help organize data clearly.
Basic Table Structure
Example:
<table>
<tr>
<th>Name</th>
<th>Role</th>
</tr>
<tr>
<td>Sachin</td>
<td>Developer</td>
</tr>
</table>
This creates a simple table with:
- headings
- rows
- columns
Understanding Table Tags
| Tag | Purpose |
|---|---|
<table> | Main table container |
<tr> | Table row |
<th> | Table heading |
<td> | Table data |
<thead> | Table header section |
<tbody> | Table body section |
<tfoot> | Table footer section |
These tags help structure table content properly.
1. tr Tag (Table Row)
The <tr> tag creates a table row.
Example:
<tr>
</tr>
Each row can contain headings or data cells.
2. th Tag (Table Heading)
The <th> tag creates heading cells.
Example:
<th>Name</th>
Browsers usually render table headings in bold text.
Common uses:
- column titles
- labels
- data categories
3. td Tag (Table Data)
The <td> tag represents normal table data.
Example:
<td>Frontend Developer</td>
This displays the actual table content.
Full Table Example
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Role</th>
</tr>
<tr>
<td>Sachin</td>
<td>sachin@example.com</td>
<td>Developer</td>
</tr>
<tr>
<td>Rahul</td>
<td>rahul@example.com</td>
<td>Designer</td>
</tr>
</table>
This structure is commonly used in admin dashboards and management systems.
thead, tbody, and tfoot
Modern tables often separate content into sections.
thead
Contains heading content.
Example:
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
tbody
Contains the main table data.
Example:
<tbody>
<tr>
<td>Sachin</td>
</tr>
</tbody>
tfoot
Contains footer information.
Example:
<tfoot>
<tr>
<td>Total Users: 50</td>
</tr>
</tfoot>
Professional Table Structure
Example:
<table>
<thead>
<tr>
<th>Name</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sachin</td>
<td>Developer</td>
</tr>
</tbody>
</table>
This is considered a cleaner and more maintainable structure.
Border Attribute
Example:
<table border="1">
This adds visible borders.
However, modern websites usually style tables using CSS instead of the border attribute.
Modern Table Styling
Example CSS:
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
border: 1px solid #ccc;
padding: 12px;
}
This creates cleaner and more professional tables.
colspan Attribute
The colspan attribute merges multiple columns.
Example:
<td colspan="2">
Full Width Cell
</td>
Useful for:
- summary rows
- pricing tables
- grouped content
rowspan Attribute
The rowspan attribute merges rows vertically.
Example:
<td rowspan="2">
Developer
</td>
Used in advanced table layouts.
Responsive Table Design
One common beginner mistake is creating tables that break on mobile devices.
Modern solution:
<div class="table-wrapper">
<table>
</table>
</div>
CSS:
.table-wrapper {
overflow-x: auto;
}
This prevents layout breaking on smaller screens.
Common Beginner Mistakes
Using tables for page layouts
Bad practice.
Tables should display data, not structure entire websites.
Use:
- Flexbox
- Grid
- semantic layout tags
for layouts instead.
Missing table headings
Always use <th> for accessibility and readability.
Ignoring responsive design
Large tables often overflow on mobile devices.
Too much nested content
Keep tables clean and readable.
Real-World Use Cases
Tables are heavily used in:
- admin panels
- analytics dashboards
- CRM systems
- invoice systems
- eCommerce products
- data management platforms
Modern SaaS applications rely heavily on structured table data.
Tables in React and Next.js
In modern frontend development, tables are often generated dynamically.
Example:
users.map((user) => (
<tr key={user.id}>
<td>{user.name}</td>
</tr>
))
This is very common in dashboard applications.
Accessibility Benefits
Properly structured tables improve:
- screen reader support
- data understanding
- keyboard navigation
- semantic structure
Semantic HTML matters even in complex applications.
Conclusion
The HTML table tag is essential for displaying structured data in web applications.
Learning tables properly helps developers build better dashboards, admin systems, analytics platforms, and data-driven interfaces.
As you move into React, Next.js, and full-stack development, tables become even more important because modern applications frequently display large amounts of structured information.