TABLES

 

GENERAL INFORMATION

 

Tables require the use of three different tags.

 

All tables start with the <table> tag and endwith the </table> tag.

 

Each row in the table starts with the <tr> tag and ends with the </tr> tag.

 

Each division within a row starts with a <td> tag and ends with a <td> tag.

 

To see the table borders, we need to set the border attribute to 1 inside the table tag.

 

Here is the basic setup for a table that is 2 x 2:

 

<table border=”1”>

<tr>

<td>Text in cell 1</td>

<td>Text in cell 2</td>

</tr>

<tr>

<td>Text in cell 3</td>

<td>Text in cell 4</td>

</table>

 

LOCATION OF USE

           

You can place the tags anywhere between the <body> and </body> tags.

 

The <tr> tags must be placed inside the table tags.

 

The <td> tags must be placed inside the <tr> tags.

 

COMMON ERRORS

 

 

OPTIONAL ATTRIBUTES - <table> TAG

 

 

This will set the value of the thickness of the border.  The default is zero so you usually want to use this attribute so that you see the border.

 

 

These two attributes are fairly obvious affecting the size of the table.  You can also specify values in percentages.

 

This attribute specifies where to align the table.  Possible values are left, center and right.

 

OPTIONAL ATTRIBUTES - <td> TAG

 

 

Sets the background colour for the cell.

 

 

Specifies how many columns that a cell should span.  The default is 1. 

 

EXAMPLE

 

Click here to see an example.  Use View Source to see the code.

 

Click here to see another example.  Use View Source to see the code.