Coding Hubs School of AI – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 8448811540
Back to HTML Notes
Topic #611

Table Caption

The <caption> element gives a table a real, semantically-attached title — describing what the table actually contains.

Syntax

<table>
    <caption>Table title</caption>
    <tr><td>...</td></tr>
</table>

Basic Example

<table>
    <caption>Course Fee Comparison</caption>
    <tr><th>Course</th><th>Fee</th></tr>
    <tr><td>Data Science</td><td>₹45,000</td></tr>
</table>

Browser output: "Course Fee Comparison" renders centered above the table by default, in normal (non-bold) text.

How It Works

<caption> must be the first child immediately inside <table> — before any <thead>, <tr>, or other content. A table can have at most one caption.

Important Attributes

AttributePurpose
— none special —Only universal global attributes apply; positioning is controlled with CSS caption-side

Real-World Example

<table>
    <caption>Student Attendance — March 2026</caption>
    <tr><th>Student</th><th>Days Present</th></tr>
    <tr><td>Aman</td><td>22</td></tr>
</table>

A specific, informative caption naming both what the table shows and the relevant time period — far more useful than a generic heading placed loosely above the table with no real connection to it.

Comparison: caption vs a heading before the table

<caption>An <h2> placed before the table
Semantic link to the tableExplicit — programmatically tied to this specific tableNone — purely visual proximity, no real connection
Screen reader behaviorAnnounced as part of navigating into the tableRead separately, with no guaranteed association

Common Mistakes

  • Using a nearby <h2>/<h3> instead of a real <caption>, losing the explicit, machine-readable connection to the table
  • Placing <caption> anywhere other than as the table's very first child

Best Practices

  • Give every meaningful table a real <caption>
  • Keep captions specific and descriptive, not generic ("Table 1")

Accessibility Considerations

A screen reader announces the caption when a user navigates into the table, immediately giving context about what they're about to hear — a real, structural benefit over a nearby but disconnected heading.

SEO Considerations

Caption text is genuine, readable content that helps search engines understand exactly what a table represents.

Browser & Modern HTML Notes

Stable and simple; CSS's caption-side property can move the caption to display below the table instead of above, without changing its position in the HTML source.

Mini Practice

  1. Add a specific, descriptive <caption> to a table currently using a nearby <h3> instead.
  2. Move a caption to render below its table using CSS caption-side: bottom;, without changing the HTML.

Related HTML Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →