KCL • CCH • Minor programme • AV1000 • Electronic communications and publishing
An HTML table has two primary uses: laying out tabular alphanumeric information and, less obviously, controlling the spatial relationships of objects on the page, especially images. Current browsers are rather poor at arranging images or images together with text when the browser window is too narrow. The table is the best means we now have of addressing that difficulty. See the page on imaging for details.
The following is a typical structure of rows and columns used to arrange alphanumeric information into self-contained areas or "cells":
| Building type | Date | Location | Architect | Description |
|---|---|---|---|---|
| Public lavatories | 1897 | Hampstead, South End Green | ? | Below ground; walls tiled in green & white, floor in black & white |
| Telephone kiosk | 1935 | Lambeth Palace Road, Albert Embankment | Sir Giles Gilbert Scott | Type K6; cast iron, square, with domed roof. |
| Terraced house | 1734; early 20C alt. | Dean Street, Westminster, W1 | John Nolloth (?) | Solid brick with red brick dressings, slate roofs, 4 stories, 3 windows wide. |
| Terraced house | 1692; 19C alt. | Dean Street, Westminster, W1 | ? | Stock brick, slate roof, 4 stories, 3 windows wide. Ground floor has 20C restaurant. |
| Hotel | 1851 | Great Northern Hotel, Pancras Road | Lewis Cubitt | Stock brick, stucco dressings, slate roof. Crescent-shaped. 5 stories plus attic and basement. |
The HTML that produces the above table looks like this (leaving out some of the later rows):
<table border="5" cellpadding="5">
<tr>
<th> Building type </th>
<th> Date </th>
<th> Location </th>
<th> Architect </th>
<th> Description </th>
</tr>
<tr>
<td> Public lavatories </td>
<td> 1897 </td>
<td> Hampstead, South End Green </td>
<td> ? </td>
<td> Below ground; walls tiled in green & white, floor in black & white </td>
</tr>
<tr>
<td> Telephone kiosk </td>
<td> 1935 </td>
<td> Lambeth Palace Road, Albert Embankment </td>
<td> Sir Giles Gilbert Scott </td>
<td> Type K6; cast iron, square, with domed roof. </td>
</tr>
…
</table>
Note the basic structure: the table as a whole (<table> … </table>) contains a set of rows (<tr> … </tr>), each of which contains a set of data-elements (<td> … </td>) within each of which the text for the cell is specified. (The <th> … </th> elements are a variant of the <td> … </td> used for headers.) Note the attributes in the <table> tag; these are explained below.
The basic elements of a table are:
| Element | Function | Contains |
|---|---|---|
| <table> … </table> | defines the table | everything else |
| <tr> … </tr> (table row) | defines a row | the following |
| <th> … </th> (table header) | provides label for column | text only |
| <td> … </td> (table data) | defines contents of a cell | text or image |
The basic attributes used in a table are:
| Element | Attribute | Values | Function |
|---|---|---|---|
| table | border | pixel value | puts a border around the cells |
| cellspacing | pixel value | puts space between cells | |
| cellpadding | pixel value | puts space between cell wall and data | |
| width | pixel value or percent | determines width of the whole table | |
| align | left or right | causes table to be placed left or right, with text flowing around | |
| valign | top or bottom | aligns text in cells at the top or bottom of the cell | |
| tr | align | left, center, right | see above |
| valign | top, middle, bottom | see above | |
| td / th | align | left, center, right | see above |
| valign | top, middle, bottom | see above | |
| colspan | nr of columns | specifies how many columns cell should span | |
| rowspan | nr of rows | specifies how many rows cell should span |
Create a new Web page consisting of a table for the major pollutants affecting life and buildings in major urban centres such as London. The columns should be labelled with the following headers:
Use the following data. Condense and abbreviate wherever possible without obscuring any of the relevant facts—i.e. try to produce a visually compact table.
revised October 2007