JavaScript Curriculum
Tables
easyThe coffee shop wants a price comparison table showing all drinks across hot, iced, and blended versions — with a merged header and row categories. Let's build it properly.
Tables
HTML tables are for one thing: tabular data — information that has a natural row-and-column structure. Price lists, schedules, comparison charts, sports results. They are not for page layout (that's CSS Grid and Flexbox's job).
The Table Element Family
A well-structured table uses six elements working together:
| <thead> / <th> | |
|---|---|
| <tbody> | <td> |
| <tbody> | <td> |
| <tfoot> | |
Groups the body rows. A table can have multiple <tbody> elements to group related rows (e.g. by category).
<tbody> <tr><td>Espresso</td><td>£2.50</td></tr> </tbody>
Spanning Cells — colspan and rowspan
Real-world tables have merged cells. HTML handles this with two attributes:
colspan="n"— a cell spansncolumns horizontallyrowspan="n"— a cell spansnrows vertically
Every cell is 1×1. No spanning.
| Drink | Size | Price |
|---|---|---|
| Espresso | Small | £2.50 |
| Latte | Medium | £3.50 |
| Cappuccino | Large | £4.00 |
<th>Drink</th> <th>Size</th> <th>Price</th>
Making Tables Accessible
A table without accessibility markup is a confusing grid for screen reader users. Three attributes fix this:
Gives the table a visible, programmatic title
<table> <caption>Monthly Coffee Sales</caption> ...
Your Challenge
Build a complete, accessible coffee menu price table with a caption, scoped headers, merged cells, and a footer row.
Challenge
Build a coffee menu table with a caption, a thead containing column headers with scope='col', a tbody with at least 3 drink rows, one cell using colspan to span two columns, and a tfoot row showing a note or total.
Tables
easyThe coffee shop wants a price comparison table showing all drinks across hot, iced, and blended versions — with a merged header and row categories. Let's build it properly.
Tables
HTML tables are for one thing: tabular data — information that has a natural row-and-column structure. Price lists, schedules, comparison charts, sports results. They are not for page layout (that's CSS Grid and Flexbox's job).
The Table Element Family
A well-structured table uses six elements working together:
| <thead> / <th> | |
|---|---|
| <tbody> | <td> |
| <tbody> | <td> |
| <tfoot> | |
Groups the body rows. A table can have multiple <tbody> elements to group related rows (e.g. by category).
<tbody> <tr><td>Espresso</td><td>£2.50</td></tr> </tbody>
Spanning Cells — colspan and rowspan
Real-world tables have merged cells. HTML handles this with two attributes:
colspan="n"— a cell spansncolumns horizontallyrowspan="n"— a cell spansnrows vertically
Every cell is 1×1. No spanning.
| Drink | Size | Price |
|---|---|---|
| Espresso | Small | £2.50 |
| Latte | Medium | £3.50 |
| Cappuccino | Large | £4.00 |
<th>Drink</th> <th>Size</th> <th>Price</th>
Making Tables Accessible
A table without accessibility markup is a confusing grid for screen reader users. Three attributes fix this:
Gives the table a visible, programmatic title
<table> <caption>Monthly Coffee Sales</caption> ...
Your Challenge
Build a complete, accessible coffee menu price table with a caption, scoped headers, merged cells, and a footer row.
Challenge
Build a coffee menu table with a caption, a thead containing column headers with scope='col', a tbody with at least 3 drink rows, one cell using colspan to span two columns, and a tfoot row showing a note or total.