HTML Tags: Tables

The only essential things on this page are:

  • <table>, <tr>, <th>, <td>
  • colspan and rowspan attributes

These are the HTML tags you use to make tables.

TagTypeDescription
<table>BlockRepresents a table
Rows and cells
<tr>OtherRepresents a table row
<th>OtherRepresents a table header cell
<td>OtherRepresents a table data cell
Row groups
<thead>OtherDefines the row group that comprises the table's header (column header rows)
<tbody>OtherDefines the row group that comprises the table's body
<tfoot>OtherDefines the row group that comprises the table's footer (summarys rows)
Column group
<colgroup>OtherDefines a column group
<col>OtherDefines a column that is part of a column group
Caption
<caption>OtherAdds 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 attributes
  • colspan=[...] — how many columns the cell extends to
  • rowspan=[...] — how many rows the cell extends to
Obscure attributes
  • 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 the id'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 attributes
  • colspan=[...] — how many columns the cell extends to
  • rowspan=[...] — how many rows the cell extends to
Obscure attributes
  • headers=[...] — adds semantic info: what are the id'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
NameTest 1Test 2
James8090
Bond70100
Average7595

<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.

Common attributes
  • span=[...] — how many columns the <colgroup> or <col> spans.
| LIVE PREVIEW
ISBNTitleOld PriceNew Price
1234567My First HTML$10$15
1234568My First CSS$12$16

<caption>

Adds table caption.

| LIVE PREVIEW
Pokémon Evolution
Basic Stage 1 Stage 2
Charmander Charmeleon Charlizard

References