HTML Tables
Turn rows and columns into something useful! Learn how to organize data, create clear headers, group information, and build accessible tables that make sense to everyone.
<table>
<tr>
<th>Skill</th>
<th>Level</th>
</tr>
<tr>
<td>HTML</td>
<td>Advanced</td>
</tr>
</table>
| Skill | Level |
|---|---|
| HTML | Advanced |
Why Use HTML Tables?
Think about a class schedule, a product comparison, or a list of monthly expenses. Sometimes information is easier to understand when it’s arranged into rows and columns.
That’s exactly what HTML tables are for: presenting data with meaningful relationships between rows and columns.
| Language | Goal |
|---|---|
| HTML | Build structured pages |
| CSS | Design beautiful layouts |
| JavaScript | Add interactivity |
Meet the Table Elements
Every table starts with <table>. Inside it, you’ll build rows using <tr>, header cells using <th>, and regular data cells using <td>.
<table>
<tr>
<th>Name</th>
<th>Favorite Language</th>
</tr>
<tr>
<td>Alex</td>
<td>HTML</td>
</tr>
<tr>
<td>Sam</td>
<td>Python</td>
</tr>
</table>
| Name | Favorite Language |
|---|---|
| Alex | HTML |
| Sam | Python |
Each <tr> creates a new row. The cells inside that row determine the columns. Your browser understands the structure even before you add CSS styling.
Give Your Table a Title and Headers
Tables become much easier to understand when readers know what the information represents.
Use <caption> for the table’s title and scope="col" or scope="row" to identify header relationships.
<table>
<caption>Weekly Study Hours</caption>
<tr>
<th scope="col">Day</th>
<th scope="col">Hours</th>
</tr>
<tr>
<th scope="row">Monday</th>
<td>2</td>
</tr>
<tr>
<th scope="row">Tuesday</th>
<td>3</td>
</tr>
</table>
| Day | Hours |
|---|---|
| Monday | 2 |
| Tuesday | 3 |
Meet the Head, Body, and Footer
For larger tables, HTML lets you group different sections with <thead>, <tbody>, and <tfoot>.
<table>
<thead>
<tr>
<th scope="col">Course</th>
<th scope="col">Hours</th>
</tr>
</thead>
<tbody>
<tr><td>HTML</td><td>3</td></tr>
<tr><td>CSS</td><td>2</td></tr>
</tbody>
<tfoot>
<tr><th scope="row">Total</th><td>5</td></tr>
</tfoot>
</table>
| Course | Hours |
|---|---|
| HTML | 3 |
| CSS | 2 |
| Total | 5 |
These sections make your code easier to read and maintain. They also give you useful hooks when styling tables with CSS.
Make Cells Span Rows or Columns
Sometimes a heading needs to stretch across multiple columns, or a category applies to several rows.
Use colspan to span columns and rowspan to span rows.
<table>
<tr>
<th colspan="2">My Learning Plan</th>
</tr>
<tr>
<th scope="col">Day</th>
<th scope="col">Topic</th>
</tr>
<tr><td>Monday</td><td>HTML</td></tr>
<tr><td>Tuesday</td><td>CSS</td></tr>
</table>
| My Learning Plan | |
|---|---|
| Day | Topic |
| Monday | HTML |
| Tuesday | CSS |
rowspan="2" in the sandbox. Remember that a cell spanning two rows occupies space in both rows, so you must account for that when adding other cells.Make Your Data Easier to Read
A little CSS can transform a plain table into something much more readable. Borders, spacing, alternating row colors, and hover effects all help.
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #cbd5e1;
padding: 12px;
text-align: left;
}
thead {
background: #dff7f4;
}
tbody tr:nth-child(even) {
background: #f1f5f9;
}
</style>
For narrow screens, put a wide table inside a container with overflow-x: auto so visitors can scroll horizontally without breaking the layout.
Build Tables Everyone Can Understand
Before publishing a table, ask yourself whether someone can understand the information quickly and navigate it easily.
- Use tables for data, not for page layout.
- Add a descriptive
<caption>when it helps explain the table. - Use real header cells and appropriate
scopeattributes. - Group complex data logically with table sections.
- Use
rowspanandcolspancarefully; complex spanning can make tables harder to navigate. - Allow wide tables to scroll on smaller screens.
- Keep data accurate, readable, and consistently formatted.
A well-structured table doesn’t just look organized. It makes information genuinely easier to use.
Build a Weekly Learning Schedule
You’ve learned the building blocks. Now create a schedule that shows what you’re studying throughout the week!
Your Mission
- Create a table with a descriptive caption.
- Add three columns: Day, Topic, and Study Time.
- Include at least four days of learning activities.
- Use
<thead>and<tbody>. - Use
scope="col"for column headings. - Add a footer showing your total study hours.
colspan. Make your table something you’d be proud to share!Build Your Table!
Edit the HTML, add your own schedule, and run the code to see your table come to life. Try different headings, rows, and styles!
What You’ve Learned
You’re Getting Organized!
You’ve turned plain information into structured, readable data. That’s a skill you’ll use in schedules, reports, dashboards, comparisons, and much more.
- How to create tables using rows and cells.
- How to add captions and accessible headers.
- How to group tables with heads, bodies, and footers.
- How to span rows and columns.
- How to style tables for readability.
Next up: Iframes — discover how to bring other content into your web pages!
Your Learning Journey
0 / 13 CompletedKeep going! Every completed lesson brings you closer to mastering Advanced HTML.
Nice Work!
You've learned how to organize information into meaningful rows and columns, create accessible headers, and build your own weekly learning schedule. You're making great progress!


