HTML Tables (see HTML4.01 specs) provide a robust way of organizing information on a web page. They can be used both to construct an overall grid-style page layout as well as for presenting specific information in a tabular fashion.
<table summary=""> <tr> <th>1990</th> <th>2000</th> <th>type</th> </tr> <tr> <td>5.31</td> <td>4.2</td> <td>percent increase</td> </tr> <tr> <td>$30,333</td> <td>$46,576</td> <td> hardware<br />and<br />software </td> </tr> </table>Here is how it is rendered:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
The control for table elements are in HTML-Kit's table tab. The icon on the far left is the most basic one which generates a starter table with one row and one cell. HTML-Kit more-or-less forces you to use the summary attribute.
A table consists of cells displayed horizontally between the <tr> </tr> tags. The td and th cells have the same function the difference is their different default style features:void, above, below, box, border hsides, vsides, lhs, rhs,
none, groups, rows, cols, all
<table summary="" border="1">causes the table to look like this:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
<table summary="" border="1" cellpadding="20px">causes the table to look like this:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
<table summary="" border="1" cellpadding="20px" cellspacing="8px">causes the table to look like this:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
The cellpadding and cellspacing both have default values of 1. In many circumstances it is useful to eliminate this spacing, causing the following change in appearance (both have border="1"):
|
cellpadding="0"
cellspacing="0" | cellpadding, cellspacing unspecified | ||||||||||||||||||
|
|
<table summary="" border="1" width="400px">causes the table to look like this:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
<table summary="" border="1" width="100%">causes the table to look like this:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
The frame and rules attributes allow you to specify variations on where the lines appear. The frame specifies the lines forming the external box around the table and the rules specify the internal lines. Here are some examples.
<table summary="" border="1" frame="border" rules="none">causes the table to look like this:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
<table summary="" border="1" frame="void" rules="all">causes the table to look like this:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
<table summary="" border="1" frame="hsides" rules="rows">causes the table to look like this:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
<table summary="" border="1" frame="hsides" rules="cols">causes the table to look like this:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
<td></td> or <td> </td>
For example, the following code:
<table summary="" cellpadding="10px" border="1"> <tr> <td>a</td> <td> </td> </tr> <tr> <td>c</td> <td>d</td> </tr> </table>creates this appearance:
| a | |
| c | d |
<td> </td>With this modification the empty cell "looks right":
| a | |
| c | d |
left, center, right, justify, charwhen char is used, also specify charOff
top, middle, bottom, baseline
related to providing tabular information in alternative modalities, such as speech synthesis. Using these, the user may be able to query the contents of the table to discover specific information.
We'll use our example table to illustrate some of these features.| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
<table summary="" border="1"> <tr align="left"> <th>1990</th> <th>2000</th> <th>type</th> </tr> <tr> <td>5.31</td> <td>4.2</td> <td>percent increase</td> </tr> <tr valign="top"> <td>$30,333</td> <td>$46,576</td> <td> hardware<br />and<br />software </td> </tr> </table>To see the difference, compare the two side by side:
|
previous version
|
modified version
|
<th align="right">type</th>we get the following effect:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | 4.2 | percent increase |
| $30,333 | $46,576 |
hardware and software |
<table summary="" border="1"> <tr> <th>1990</th> <th>2000</th> <th>type</th> </tr> <tr> <td align="center" colspan="2">5.31</td> <td>percent increase</td> </tr> <tr> <td>$30,333</td> <td>$46,576</td> <td> hardware<br />and<br />software </td> </tr> </table>creates this appearance:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | percent increase | |
| $30,333 | $46,576 |
hardware and software |
We are trying to convey the information that the number "5.31" applies to both years instead of repeating it. Whenever a colspan > 1 is used, we simply reduce the number of cells within a row appropriately.
Likewise, the rowspan attribute, when set to a number > 1 means that the cell covers that one in the row where it is declared and the row below it. This is a bit trickier to use, because you have to take away a cell in the next row! Here is an example:<table summary="" border="1"> <tr> <th>1990</th> <th>2000</th> <th>type</th> </tr> <tr> <td>5.31</td> <td align="center" rowspan="2">?</td> <td>percent increase</td> </tr> <tr> <td>$30,333</td> <td> hardware<br />and<br />software </td> </tr> </table>creates this appearance:
| 1990 | 2000 | type |
|---|---|---|
| 5.31 | ? | percent increase |
| $30,333 |
hardware and software |