Extensions to the <TABLE> tag, supported by Netscape, include BORDER, CELLPADDING, CELLSPACING, and WIDTH. You can assign a number to BORDER to specify the width, in pixels, of the outside table border. You can also assign a number to CELLPADDING defining the space (in pixels) between the cell contents and the cell borders, while CELLSPACING defines the space between the cells (the width of the borders).
Finally, the WIDTH attribute sets the width of the entire table. This can be expressed as an absolute number (in pixels) or as a percentage width of the entire display.
This page starts (section A) with a series of tables which demonstrate the available options. Then (section B) each table is shown together with the HTML source code which produces it.
Click on the label of any table to go to its counterpart in the other section.
Example 1: plain (no borders)
|
Example 2: with border
| ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Example 4: with border and cellpadding
| ||||||||||||||||||||||||
Example 5: with ``header cells''
|
Example 6: Overriding cell style defaults
| ||||||||||||||||||||||||
|
| ||||||||||||||||||||||||
|
Example 10: colspan and rowspan
| ||||||||||||||||||||||||
Example 11: tables within a table
|
Example 12: <pre>preformatting</pre>
|
Example 13: the WIDTH attribute
width=50% | width=35% | XXX |
---|---|---|
A | B | C |
D | E | F |
Example 1: plain (no borders)
|
| | | | | | | | | | | | | | | | | | | | <table> <tr> <td>Item A1</td> <td>Item A2</td> <td>Item A3</td> </tr> <tr> <td>Item B1</td> <td>Item B2</td> <td>(this is B3)</td> </tr> <tr> <td>Item C1</td> <td>-C2-</td> <td>*C3*</td> </tr> <tr> <td>Item number D1</td> <td>Item D2</td> <td>Item D3</td> </tr> </table> |
---|
Example 2: with border
|
| | | | | | | | | | | | | | | | | | | | <table border=3> <tr> <td>Item A1</td> <td>Item A2</td> <td>Item A3</td> </tr> <tr> <td>Item B1</td> <td>Item B2</td> <td>(this is B3)</td> </tr> <tr> <td>Item C1</td> <td>-C2-</td> <td>*C3*</td> </tr> <tr> <td>Item number D1</td> <td>Item D2</td> <td>Item D3</td> </tr> </table> |
---|
Example 3: with cellpadding
|
| | | | | | | | | | | | | | | | | | | | <table cellpadding=5> <tr> <td>Item A1</td> <td>Item A2</td> <td>Item A3</td> </tr> <tr> <td>Item B1</td> <td>Item B2</td> <td>(this is B3)</td> </tr> <tr> <td>Item C1</td> <td>-C2-</td> <td>*C3*</td> </tr> <tr> <td>Item number D1</td> <td>Item D2</td> <td>Item D3</td> </tr> </table> |
---|
Example 4: with border and cellpadding
|
| | | | | | | | | | | | | | | | | | | | <table border=3 cellpadding=5> <tr> <td>Item A1</td> <td>Item A2</td> <td>Item A3</td> </tr> <tr> <td>Item B1</td> <td>Item B2</td> <td>(this is B3)</td> </tr> <tr> <td>Item C1</td> <td>-C2-</td> <td>*C3*</td> </tr> <tr> <td>Item number D1</td> <td>Item D2</td> <td>Item D3</td> </tr> </table> |
---|
Example 5: with ``header cells''
|
| | | | | | | | | | | | | | | | | | | | <table border=3 cellpadding=5> <tr> <th>Item A1</th> <th>Item A2</th> <th>Item A3</th> </tr> <tr> <td>Item B1</td> <td>Item B2</td> <td>(this is B3)</td> </tr> <tr> <td>Item C1</td> <td>-C2-</td> <td>*C3*</td> </tr> <tr> <td>Item number D1</td> <td>Item D2</td> <td>Item D3</td> </tr> </table> |
---|
Example 6: Overriding the defaults for <td> and <th>
|
| | | | | | | | | | | | | | | | | | | | <table border=7 cellpadding=5> <tr> <th align=right>Item A1</th> <th>Item <i>A2</i></th> <th>Item A3</th> </tr> <tr> <td>Item B1</td> <td>Item B2</td> <td>(this is B3)</td> </tr> <tr> <td align=center>Item C1</td> <td>-C2-</td> <td>*C3*</td> </tr> <tr> <td>Item <b>number D1</b></td> <td>Item D2</td> <td align=right>Item D3</td> </tr> |
---|
Example 7: empty cells
|
| | | | | | | | | | | | | | | | | | | | <table border=3 cellpadding=5> <tr> <td> </td> <td>Item A2</td> <td>Item A3</td> </tr> <tr> <td>Item B1</td> <td>Item B2</td> <td> </td> </tr> <tr> <td>Item C1</td> <td>-C2-</td> <td> </td> </tr> <tr> <td>Item number D1 </td> <td> </td> <td> </td> </tr> </table> |
---|
Example 8: colspan
|
| | | | | | | | | | | | | | | | | | | | <table border=3 cellpadding=5> <tr> <td colspan=2>Items A1, A2</td> <td>Item A3</td> </tr> <tr> <td>Item B1</td> <td>Item B2</td> <td>(this is B3)</td> </tr> <tr> <td>Item C1</td> <th colspan=2>Items C2 and C3</th> </tr> <tr> <td colspan=3>The items labelled D1, D2, and D3</td> </tr> </table> |
---|
Example 9: rowspan
|
| | | | | | | | | | | | | | | | | | | | <table border=3 cellpadding=5> <tr> <td>Item A1</td> <td>Item A2</td> <th rowspan=3>Items A3, <br> B3, <br> C3 </th> </tr> <tr> <td>Item B1</td> <td>Item B2</td> </tr> <tr> <td rowspan=2>Items C1 and D1</td> <td>-C2-</td> </tr> <tr> <td>Item D2</td> <td>Item D3</td> </tr> </table> |
---|
Example 10: colspan and rowspan
|
| | | | | | | | | | | | | | | | | | | | <table border=3 cellpadding=5> <tr> <td rowspan=2>Items A1,<br>B1</td> <td colspan=2>Items A2, A3</td> </tr> <tr> <th colspan=2>Items B2, B3</th> </tr> <tr> <th>Item C1</th> <td rowspan=2> C2,D2 </td> <td>*C3*</td> </tr> <tr> <td>Item number D1</td> <td>Item D3</td> </tr> </table> |
---|
Example 11: tables within a table
|
| | | | | | | | | | | | | | | | | | | | <table border=3 cellpadding=5> <tr> <td><table border> <tr> <td>A1a1</td> <td>A1a2</td> </tr> <tr> <td>A1b1</td> <td>A1b2</td> </tr> </table></td> <td>A2</td> <td>A3</td> </tr> <tr> <td>B1</td> <td>B2</td> <td>B3</td> </tr> <tr> <td>C1</td> <td><table cellpadding=4> <tr> <td>A1a1</td> <td>A1a2</td> </tr> <tr> <td>A1b1</td> <td>A1b2</td> </tr> </table></td> <td>C3</td> </tr> </table> |
---|
Example 12: <pre>preformatting</pre>
|
| | | | | | | | | | | | | | | | | | | <pre> $ 10.98 $305.20 $ 29.95 $ 3.16 11.05 291.80 39.95 0.87 12.77 290.10 19.95 0.23 23.51 301.40 9.95 0.79 7.39 306.90 99.95 1.50 20.16 295.30 79.95 0.90 </pre> |
---|
Example 13: the WIDTH attribute
<Table Width=75%> specifies a table 75% of the full width of the Netscape window. <TH Width=50%> (or TD) specifies that the cell be 50% of the full table width. |
| | | | | | | | | | | | | | | | | | | |
<table width=75% border=3 cellpadding=2> <tr> <TH WIDTH=50%> 50%</TH> <TH WIDTH=35%> 35%</TH> <TH> XXX </TH> </tr> <tr> <td>A</td> <td>B</td> <td>C</td> </tr> <tr> <td>D</td> <th><i>E</i></th> <td>F</td> </tr> </table> |
---|