table
The data grid container.
Learn table, thead, tbody, tr, th, td as part of the HTML element system: when to use it, how it fits inside a document and what mistakes to avoid.
Tables
A table describes relationships between rows and columns. It is perfect for schedules, comparisons, financial data, results and other grid-like information.
Tables become powerful when headers, captions and scopes are clear. They become painful when used as layout hacks.
table, thead, tbody, tr, th, td. Real structured data, never layout hacks. Syntax in context
Use th for headers and scope where needed, so users and tools can connect each data cell to the right label.
<table>
<caption>Course modules</caption>
<thead>
<tr><th scope="col">Module</th><th scope="col">Level</th></tr>
</thead>
<tbody>
<tr><td>HTML</td><td>Beginner</td></tr>
<tr><td>APIs</td><td>Intermediate</td></tr>
</tbody>
</table>
Good versus weak
<table>
<caption>Course modules</caption>
<thead>
<tr><th scope="col">Module</th><th scope="col">Level</th></tr>
</thead>
<tbody>
<tr><td>HTML</td><td>Beginner</td></tr>
<tr><td>APIs</td><td>Intermediate</td></tr>
</tbody>
</table>
<table> <tr><td><h1>Page title</h1></td><td>Sidebar</td></tr> </table>
Rules that matter
Tables should represent row-column relationships.
Use th for labels, not styled td elements.
A caption can explain what the table represents.
Use CSS grid or flexbox for layout.
Attributes such as border, cellpadding and cellspacing belong to old presentational HTML. Use CSS instead.
Production thinking
Beginners often ask why this is not just a div with styling. The reason is that HTML is read by browsers, search engines, screen readers and future developers. Clear meaning makes the page easier to use and maintain.
Headers and captions help screen reader users understand how cells relate to rows and columns.
Tables need responsive planning. Wide data tables often need horizontal scroll or a mobile-specific presentation.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.