Tables
Web development I: Front-end engineering
How tables are used
Tables are for tabular data
● Cells arranged into rows and columns
Basic markup
See <th> (table heading), <tr> (table row), <td> (table data)
Semantic markup
<table> The table element
<caption> Table caption: describe content
<colgroup> Group of columns
<col> Column description
<thead> Table header: column names
<tbody> Table body: primary content
<tfoot> Table footer: secondary content
Spanning cells
<table>
<tr>
<th colspan="2">Fat</th>
</tr>
<tr>
<td>Saturated Fat (g)</td>
<td>Unsaturated Fat (g)</td>
</tr>
</table>
Spanning cells
<table>
<tr>
<th rowspan="3">Serving Size</th>
<td>Small (8oz.)</td>
</tr>
<tr>
<td>Medium (16oz.)</td>
</tr>
<tr>
<td>Large (24oz.)</td>
</tr>
</table>
Space in and between cells
Cell padding Cell spacing
Connecting cells and headers
Scope Headers
<tr> <tr>
<th scope="row">Mars</th> <th id="diam">Diameter (in cm)</th>
<td>.95</td> …
<td>.62</td> <td headers="diam">.38</td>
<td>0</td> </tr>
</tr>
Both are extremely useful for accessibility reasons