HTML Tutorial Tables

HTML tables are defind using rows and columns. Fist we must oben our table using <table>, rows are defined using the tag <tr> for table row, we must remember to always close the row with </tr>. Table columns are defined using the tag <td> table data, this must appear inside the <tr> tag, again we must close this tag using the </td> tag. When finished we can close out our table with the </table> tag.

Example of the code for a basic table.

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
<td>row 1, cell 3</td>
<td>row 1, cell 4</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
<td>row 2, cell 3</td>
<td>row 2, cell 4</td>
</tr>
</table>
row 1, cell 1 row 1, cell 2 row 1, cell 3 row 1, cell 4
row 2, cell 1 row 2, cell 2 row 2, cell 3 row 2, cell 4

HTML Attribute Example

<table bgcolor="red" border="2" cellspacing="5" >
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>

row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2

  • In the first row of the code abovewe have defined a background colour of red attatching the code bgcolor="red"
  • A border of 2 has been applied using the code border="2"
  • Also on the first row of the code above we have included a spacing of 5 using the code code cellspacing="5"

comments powered by Disqus