Defining a table structure

Defining a table structure

Definition of a table structure starts with <table> tag, which requires a closing one (</table>). The "border" attribute of this tag specifies the width of the table border in pixels.

The table consists of rows, which are defined by using the <tr> and </tr> tags.

Each row consists of cells, which are defined by using the <td> and </td> tags. Another possibility to define a table cell is to use the <th> and </th> tags. The difference between these tags is the in the second case the cell contents will be automatically centered and put in a bold font.

The table might have a caption created as follows:

<caption>caption text</caption>

The caption will by default be put above the table and centered.

Putting all together, consider the following example:

LayoutHTML tags
Table 1
Col1 Col2 Col3
First cell Second cell Third cell
Forth cellFifth cellSixth cell
<table>
<caption>Table 1</caption>
<tr>
  <th>Col1</th> <th>Col2</th> <th>Col3</th>
</tr>
<tr>
  <td>First cell</td> <td>Second cell</td> 
  <td>Third cell</td>
</tr>
<tr>
  <td>Forth cell</td> <td>Fifth cell</td> 
  <td>Sixth cell</td>
</tr>
</table>




Controlling table border

The border attribute controls the width of the table border:

<table border="value">

where the value is the width of the border in pixels. The default width is 1 pixel.

border="0"border="5" border="10"
AB
CD
AB
CD
AB
CD