HTML Tables: table, tr, th, td, caption, thead, tbody, tfoot, colspan, rowspan and Accessible Data Tables

HTML5 and CSS3 45 min min read Updated: Nov 17, 2026 Beginner
HTML Tables: table, tr, th, td, caption, thead, tbody, tfoot, colspan, rowspan and Accessible Data Tables
Beginner Topic 1 of 3

When to Use a Table

Use a table for data that has rows and columns, like a price list or schedule. Do not use tables to place the page layout. Use CSS for that.

A Basic Table

html <table> <caption>Monthly Plans</caption> <thead> <tr> <th scope="col">Plan</th> <th scope="col">Price</th> <th scope="col">Users</th> </tr> </thead> <tbody> <tr> <th scope="row">Basic</th> <td>$9</td> <td>1</td> </tr> <tr> <th scope="row">Team</th> <td>$29</td> <td>10</td> </tr> </tbody> <tfoot> <tr> <td colspan="3">Prices shown per month</td> </tr> </tfoot> </table>
TagMeaning
tableThe whole table
captionA title for the table
thead, tbody, tfootHeader, body and footer groups
trA row
thA header cell, bold and centered by default
tdA data cell

Joining Cells

html <tr> <td colspan="2">Spans two columns</td> <td rowspan="2">Spans two rows</td> </tr> <tr> <td>A</td> <td>B</td> </tr>

Make It Accessible

  • Use th for headers and scope="col" or scope="row"
  • Add a caption so people know what the table is about
  • Keep tables simple. Avoid many merged cells

Style the Table with CSS

css table { border-collapse: collapse; width: 100%; max-width: 40rem; } caption { font-weight: bold; text-align: left; padding: .5rem 0; } th, td { border: 1px solid #ccd3dd; padding: .6rem .8rem; text-align: left; } thead th { background: #0b5fff; color: #fff; } tbody tr:nth-child(even) { background: #f3f6fb; }
Wide tables on phones Wrap a wide table in a div with overflow-x: auto so it scrolls sideways instead of breaking the page.

Practice

  1. Create a weekly timetable table
  2. Use colspan for a title cell
  3. Add zebra stripes and a header color with CSS

Conclusion

Tables are for data. Use thead, tbody, th with scope and a caption, and style them with CSS.

Quick Summary: When to use; basic table; merging; accessibility; CSS styling.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators