HTML & Web Development 7. HTML Tables 12 mins read 16,805 views

HTML Tables: Tags, Structure, and Examples

An HTML table arranges data into a two-dimensional grid of rows and columns using the element. A fully accessible, semantic table is divided into three structu...
Published: Nov 1, 2026Last Updated: Nov 21, 2026Curriculum: Class 12 / AP Physics / JEE-NEETReviewed by: OperateTools Editorial Board
Quick Summary & Direct Answer (AEO / GEO Extraction)

What is HTML Tables: Tags, Structure, and Examples? An HTML table arranges data into a two-dimensional grid of rows and columns using the element. A fully accessible, semantic table is divided into three structu...

Audience & Scope: Students, educators, and candidates preparing for academic examinations and technical assessments in Html & Web Development.
What is the proper semantic structure of an HTML table (table, thead, tbody, tfoot)?
An HTML table arranges data into a two-dimensional grid of rows and columns using the <table> element. A fully accessible, semantic table is divided into three structural sections: <thead> (header rows with <th>), <tbody> (body rows with <td>), and <tfoot> (summary/total rows).

Explanation & In-Depth Details

1) Core Table Building Blocks:
- <table>: The root container element for tabular data.
- <tr> (Table Row): Encloses a single horizontal row of cells.
- <th> (Table Header): Defines a header cell, rendered bold and centered by default.
- <td> (Table Data): Defines a regular data cell containing text, numbers, or links.

2) Semantic Partitioning:
- <thead>: Groups the table's header row(s). Browsers can repeat <thead> at the top of every printed page when printing long multipage tables.
- <tbody>: Contains the primary data records. Multiple <tbody> elements can exist in a single table to group related data sets.
- <tfoot>: Summarizes calculations, grand totals, or averages at the bottom of the table.

3) Tabular Data Only Rule: Tables must strictly be reserved for structured two-dimensional data (financial reports, employee lists, flight schedules, analytics matrices). Never use tables to structure webpage layouts.

4) Screen Reader Accessibility: When using <th> with the 'scope' attribute (scope="col" or scope="row"), screen readers announce the corresponding header aloud as a user navigates between individual cells.

5) CSS Border Collapsing: By default, browsers render double borders between table cells. Applying CSS 'border-collapse: collapse;' combines adjacent borders into clean, single lines.

Code Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Semantic HTML Table</title>
    <style>
        table { width: 100%; max-width: 650px; border-collapse: collapse; font-family: system-ui, sans-serif; }
        th, td { border: 1px solid #cbd5e1; padding: 10px 14px; text-align: left; }
        th { background: #f1f5f9; color: #0f172a; }
        tfoot td { font-weight: bold; background: #f8fafc; }
        tbody tr:hover { background: #f8fafc; }
    </style>
</head>
<body>
    <h2>Quarterly Financial Performance</h2>
    <table>
        <thead>
            <tr>
                <th scope="col">Department</th>
                <th scope="col">Q1 Revenue</th>
                <th scope="col">Q2 Revenue</th>
                <th scope="col">Growth</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Enterprise Cloud</td>
                <td>$1,240,000</td>
                <td>$1,580,000</td>
                <td>+27.4%</td>
            </tr>
            <tr>
                <td>Developer Tools</td>
                <td>$820,000</td>
                <td>$995,000</td>
                <td>+21.3%</td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td>Total Revenue</td>
                <td>$2,060,000</td>
                <td>$2,575,000</td>
                <td>+25.0%</td>
            </tr>
        </tfoot>
    </table>
</body>
</html>

Interview Question & Tips

Q1: What is the benefit of dividing tables into <thead>, <tbody>, and <tfoot>?
A1: Semantic partitioning allows long tables to scroll the <tbody> independently with CSS, enables browsers to repeat <thead> and <tfoot> on printed multi-page documents, and provides structured landmarks for screen readers.

Q2: Why should <th> always have a 'scope' attribute?
A2: The 'scope="col"' or 'scope="row"' attribute explicitly associates headers with their columns or rows, allowing assistive screen readers to announce the column title whenever a user navigates data cells.

Q3: Can a <td> element contain another HTML table?
A3: Yes, HTML permits nesting tables inside <td> elements, though it often creates complex markup that should be avoided unless strictly necessary for multi-dimensional data.

Best Practices

Always structure tables with <thead>, <tbody>, and <tfoot>, use <th> with scope attributes, and apply border-collapse: collapse in CSS.
Academic Standards & Verified Citations

This study reference for HTML Tables: Tags, Structure, and Examples is curated and verified against recognized curriculum benchmarks, peer-reviewed textbooks, and official technical documentation:

HTML & Web Development