HTML Tags: Tables
The only essential things on this page are:
<table>,<tr>,<th>,<td>colspanandrowspanattributes
These are the HTML tags you use to make tables.
| Tag | Type | Description |
|---|---|---|
<table> | Block | Represents a table |
| Rows and cells | ||
<tr> | Other | Represents a table row |
<th> | Other | Represents a table header cell |
<td> | Other | Represents a table data cell |
| Row groups | ||
<thead> | Other | Defines the row group that comprises the table's header (column header rows) |
<tbody> | Other | Defines the row group that comprises the table's body |
<tfoot> | Other | Defines the row group that comprises the table's footer (summarys rows) |
| Column group | ||
<colgroup> | Other | Defines a column group |
<col> | Other | Defines a column that is part of a column group |
| Caption | ||
<caption> | Other | Adds a table caption |
<table>
Represents a table.
| LIVE PREVIEW
| No. | Name | Address |
|---|---|---|
| 1 | John Doe | Sydney, Australia |
| 2 | Takara Tomy | Kyushu, Japan |
<tr>
Represents a table row (row of cells in table).
<th>
Defines a table header cell.
Common attributescolspan=[...]— how many columns the cell extends torowspan=[...]— how many rows the cell extends to
abbr=[...]— short abbreviated description of the cell's content (e.g. for screen readers)scope=[...]— adds semantic info: what's the scope of the header cell. Can be:row(the header is associated with this row)col(the header is associated with this column)rowgroup(the header is associated with a group of rows)colgroup(the header is associated with a group of columns)auto(the default value)
headers=[...]— adds semantic info: what are theid's of the this cell's parent<th id="...">cells (separated by space).
| LIVE PREVIEW
| Name | |
|---|---|
| First Name | Last Name |
<td>
Defines a table data cell.
Common attributescolspan=[...]— how many columns the cell extends torowspan=[...]— how many rows the cell extends to
headers=[...]— adds semantic info: what are theid's of the this cell's parent<th id="...">cells (separated by space).
| LIVE PREVIEW
| 1 | 2 | |
| 3 | ||
| 4 | 5 | 6 |
<thead>, <tbody>, and <tfoot>
Add semantics: which rows are part of the table header, table body, and table footer. (On their own they don't do anything.)
| LIVE PREVIEW
| Name | Test 1 | Test 2 |
|---|---|---|
| James | 80 | 90 |
| Bond | 70 | 100 |
| Average | 75 | 95 |
<colgroup> and <col>
Add semantics: declares which columns form a column group.
You normally put <col> inside <colgroup> to signify that those columns have the same semantics.
span=[...]— how many columns the<colgroup>or<col>spans.
| LIVE PREVIEW
| ISBN | Title | Old Price | New Price |
|---|---|---|---|
| 1234567 | My First HTML | $10 | $15 |
| 1234568 | My First CSS | $12 | $16 |
<caption>
Adds table caption.
| LIVE PREVIEW
| Basic | Stage 1 | Stage 2 |
|---|---|---|
| Charmander | Charmeleon | Charlizard |
References
- HTML elements reference (MDN) — https://developer.mozilla.org/en-US/docs/Web/HTML/Element#table_content
- HTML <th> headers Attribute (W3Schools) — https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_th_headers
- HTML <colgroup> Tag (W3Schools) — https://www.w3schools.com/tags/tag_colgroup.asp