Topic 37 of 57 7. HTML Tables Interactive Tutorial

HTML Table Header and Caption: TH and CAPTION Tags Explained

11 mins read Last updated: 12 Nov 2026 14,900 views

Topic Overview & Definition

Key Question
How do <caption> and <th> tags make HTML tables accessible to screen readers?
Direct Answer & Overview
The element provides a descriptive, visible title for an HTML table and must be placed immediately following the opening tag. The
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.

Comprehensive Step-by-Step Concepts

1) The Table Caption (
): - Must be the immediate first child of the 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 () because screen readers will not register it as a column heading.

Runnable HTML5 Code Example & Practical Implementation

index.html
HTML Editor
<!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>

Key Takeaways, Best Practices & Standards

Best Practice & Standards
Always include a
): - 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 : - 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,
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
with a styled bold (e.g. Header
immediately after , and use
with scope="col" or scope="row" for 100% WCAG accessibility.

Common Technical & Interview Questions

Q

Q1: Where must the

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

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.
Q

Q3: Can a table contain multiple

tags?
A3: No. A table may contain at most one
element.
We value your privacy & transparency

OperateTools uses cookies and local storage to ensure basic tool functionality, preserve preferences, and analyze aggregated traffic. We never sell your personal data or index your document files. Learn more in our Privacy Policy.