The <table>
tag declares the beginning of a table. The <tr>
tag means "Table Row" and the <td>
tags means "Table Data". In the above example there is one row and three different data fields in that row. Notice the opening and closing table row tags (<tr> and </tr>)
and the three table data tags (<td> and </td>
). If you are not nesting one table inside of another, no closing tag is needed for table data. If you are doing complex tables it is essential to put in the closing table data tag (</td>
).
Another new tag in this lesson is the line break tag, <br>
.
As expected it will cause a line break (like pressing return) wherever the <br> tag is used. In the table example above, the header "The World Wide Web Was Willy Wild" is on two different lines as a result of the <br> tag.
Look at the entire HTML document. Do you know what all of the tags mean and how they affect the look of the document in the browser? Let's go through the HTML table line by line.
First a center tag (<center>
), so that the whole table will be centered. This tag has nothing to do with tables, it's used here just because I wanted to position the table in the center of the page.
Next the opening table tag (<table>)
with a border attribute set to 5. This will put a border 5 pixels wide around the entire table.
Next is a table row tag (<tr>)
. The table row tag defines the beginning of a row in the table. It should be followed by one or more table data tags. (<td>)
.
In this example there are three pairs of table data tags (<td>...</td>
). The first pair of table data tags contain the header "Hello", the second pair of table data tags contain the header "The World Wide Web Was Willy Wild", the last pair of table data tags contain the header "World".
Finally the closing table tag (</table>
) and the closing center tag (</center>
).
The indentation is purely for convenience, it is not necessary. The table could have been written as follows but it is difficult to decipher in this form:
<center><table border=5><tr><td><h1>Hello</h1></td><td><center><h2>The World Wide Web <br>Was Willy Wild</h2></center></td><td><h1>World</h1></td></tr></table></center>