HTML & Web Development 7. HTML Tables 11 mins read 14,905 views

HTML Table Header and Caption: TH and CAPTION Tags Explained

The element provides a descriptive, visible title for an HTML table and must be placed immediately following the opening tag. The element defines header cell...
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 Table Header and Caption: TH and CAPTION Tags Explained? The element provides a descriptive, visible title for an HTML table and must be placed immediately following the opening tag. The element defines header cell...

Audience & Scope: Students, educators, and candidates preparing for academic examinations and technical assessments in Html & Web Development.
How do <caption> and <th> tags make HTML tables accessible to screen readers?
The <caption> element provides a descriptive, visible title for an HTML table and must be placed immediately following the opening <table> tag. The <th> element defines header cells for columns or rows, enhanced by the 'scope' attribute (scope="col" or scope="row") so screen readers announce headers for every data cell.

Explanation & In-Depth Details

1) The Table Caption (<caption>):
- Must be the immediate first child of the <table> tag.
- Acts as the visible heading and accessibility title for the table.
- Screen readers announce the caption first, allowing visually impaired users to decide whether to read the table or skip it.

2) The Table Header (<th>):
- Defines the label of a column or row.
- Rendered in bold typeface and centered by default.
- Communicates cell relationships to search engines and assistive technology.

3) The 'scope' Attribute on <th>:
- scope="col": Indicates the header applies to all cells in the vertical column below it.
- scope="row": Indicates the header applies to all cells in the horizontal row to its right.
- scope="colgroup" & scope="rowgroup": Applied to multi-level grouping headers.

4) Caption Styling with CSS: By default, <caption> renders at the top of the table. Using the CSS 'caption-side: bottom;' property, you can position the caption at the footer of the table if desired.

5) Avoiding Ambiguous Table Cells: Never replace <th> with a styled bold <td> (e.g. <td><strong>Header</strong></td>) because screen readers will not register it as a column heading.

Code Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Accessible Table with Caption</title>
    <style>
        table { border-collapse: collapse; width: 100%; max-width: 600px; font-family: sans-serif; }
        caption { font-size: 1.2rem; font-weight: bold; margin-bottom: 10px; text-align: left; color: #0f172a; }
        th, td { border: 1px solid #cbd5e1; padding: 8px 12px; }
        th { background: #e2e8f0; }
    </style>
</head>
<body>
    <table>
        <!-- Caption must immediately follow <table> -->
        <caption>Employee Attendance and Overtime Hours (September 2026)</caption>
        <thead>
            <tr>
                <th scope="col">Employee Name</th>
                <th scope="col">Department</th>
                <th scope="col">Regular Hours</th>
                <th scope="col">Overtime Hours</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th scope="row">Sarah Connor</th>
                <td>Engineering</td>
                <td>160</td>
                <td>18</td>
            </tr>
            <tr>
                <th scope="row">John Wick</th>
                <td>Security Operations</td>
                <td>160</td>
                <td>24</td>
            </tr>
        </tbody>
    </table>
</body>
</html>

Interview Question & Tips

Q1: Where must the <caption> tag be placed inside an HTML table?
A1: According to W3C specifications, the <caption> element must be the immediate first child tag directly after the opening <table> tag. Placing it anywhere else is invalid HTML.

Q2: What is the difference between scope="col" and scope="row"?
A2: 'scope="col"' links a header to all cells in its vertical column. 'scope="row"' links a header cell (often in the first column) to all data cells in that horizontal row.

Q3: Can a table contain multiple <caption> tags?
A3: No. A table may contain at most one <caption> element.

Best Practices

Always include a <caption> immediately after <table>, and use <th> with scope="col" or scope="row" for 100% WCAG accessibility.
Academic Standards & Verified Citations

This study reference for HTML Table Header and Caption: TH and CAPTION Tags Explained is curated and verified against recognized curriculum benchmarks, peer-reviewed textbooks, and official technical documentation:

HTML & Web Development