HTML Tables & Tabular Data
When you have structured data like course fees, schedules, or product comparisons, HTML tables provide the semantic solution.
What is it?
The `<table>` element represents data in a two-dimensional grid of rows (`<tr>`) and cells (`<th>` for headers, `<td>` for data).
Why is it used?
Tables organize complex data into scannable columns and rows. Screen readers can announce headers as users navigate across cells.
Detailed Explanation
A complete semantic table includes:
• `<caption>`: Title of the table.
• `<thead>`: Groups header content.
• `<tbody>`: Groups body data rows.
• `<tfoot>`: Groups summary/footer totals.
• `<th>`: Header cell (bold and centered by default, supports `scope="col"` or `scope="row"`).
• `<td>`: Standard data cell.
• `colspan` and `rowspan`: Attributes to merge columns or rows.
Syntax Structure
Syntax Blueprint
<table>
<caption>Table Title</caption>
<thead>
<tr>
<th scope="col">Header 1</th>
<th scope="col">Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</tbody>
</table>
Code Example
HTML Code
<table>
<caption>IGM Computers - Popular KLiC Certifications</caption>
<thead>
<tr>
<th scope="col">Course Name</th>
<th scope="col">Duration</th>
<th scope="col">Skill Level</th>
<th scope="col">Tuition</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data Analytics & Visualisation</td>
<td>2.5 Months</td>
<td>Beginner</td>
<td>₹2,500</td>
</tr>
<tr>
<td>Advanced Python & Flask</td>
<td>2.5 Months</td>
<td>Intermediate</td>
<td>₹2,500</td>
</tr>
<tr>
<td>C and C++ Programming</td>
<td>2 Months</td>
<td>Beginner</td>
<td>₹2,500</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">Special Career Bundle (Any 3 Courses)</td>
<td><strong>₹5,397</strong></td>
</tr>
</tfoot>
</table>
Explanation of the Code
• `scope="col"` aids accessibility by clarifying that the header applies to that column.
• `colspan="3"` merges three columns in the footer row for the bundle promotion.
Expected Output
A 4-column structured table displaying courses, durations, levels, fees, and a merged summary footer row.
Real-World Application
Used in financial portals, student grade sheets, sports scoreboards, and pricing comparison tables.
Common Mistakes to Avoid
• Using tables for website layouts (use CSS Flexbox/Grid instead!). Tables are strictly for tabular data.
• Omitting `<thead>` and `<th>`, which impairs accessibility.
Quick Practice Challenge
Create a 3-row, 3-column table showing your weekly study schedule (Day, Subject, Hours).
Key Takeaways
• Tables are exclusively for tabular data, never for page layouts.
• Always structure tables with `<thead>`, `<tbody>`, and `<th>` elements.
• Use `colspan` and `rowspan` to merge adjacent cells.