HTML <table> tags
organizing similar records of data together on a webpage
Tables display groups of similar data as a grid-like structure:
Rows typically show data observations of individual phenomena
Table typically show values that describe those individuals
For example:
A row could show a city
Each column could show data that describes a single city, e.g.
country
population
mayor
Structure
As part of semantic HTML, <table>
tags allow us to make "two-dimensional lists" with headers, rows, columns and footers:
Elements
We will look at the tags above in the table below:
<table>
0
the table
<caption>
1
a write-up explaining the table (usually used for screen readers for accessibility and hidden from sighted users)
<thead>
1
table heading section (usually a row to describe each column)
<tr>
2
table row
<th>
3
table heading
<tbody>
1
table body (main content)
<td>
3
table definition (data cell)
<tfoot>
1
table footer (usually a row for numerical totals)
Attributes
One attribute to note is scope
for table headings; these simply denote whether the heading refers to:
items that appear vertically below that heading as a column (
col
)items that follow that heading as a row (
row
)
Older attributes used to live in the <table>
tag (e.g. cellspacing
and cellpadding
) but CSS takes care of them of these days!
Web developers formerly used the <table>
tag for layout purposes to divide up sections of a page
However, this practice has become highly frowned upon and we prefer to use the <div>
tag today!
Last updated