HTML: table
Use <table> when data has meaningful row-and-column relationships, such as prices, schedules, or comparisons.
What you will learn
- How to structure a table with headings and data cells
- How
caption,th, andscopehelp readers - How to make a wide table usable on small screens
Minimal example
<table>
<caption>Opening hours</caption>
<thead><tr><th scope="col">Day</th><th scope="col">Hours</th></tr></thead>
<tbody><tr><th scope="row">Monday</th><td>9:00–17:00</td></tr></tbody>
</table><th> identifies a heading cell. Use scope="col" or scope="row" to make its relationship explicit, especially for assistive technology.
Common mistakes
- Do not use tables only to position page elements; use CSS layout for that.
- Do not leave a data table without meaningful headings or a caption when context is unclear.
- For a wide table, allow horizontal scrolling instead of shrinking text until it becomes unreadable.