The Basics of TablesThis is the first of four pages detailing one of the most important aspects of HTML, tables. Tables can be used to organize information into a sensible array, but they are most useful for creating interesting page layouts. Many people, HTML literate or otherwise, are familiar with "Frames" which can divide a page into several distinct sections. Tables are often used in place of frames for this purpose. The First StepsEvery table will begin and end the same way; using the
tags <table> and </table>. Anything that will
be part of the table must appear between these tags.
There are four very imortant points to remember when
making tables:
| |||||||||||||||||||||||||||||||||||||||||||||
The Basic Elements of a Table<tr> (Table Row) <td> (Data Cell) <th> (Header Cell) Basic Table Setup
This will create a single cell table with an invisible border. It won't look like much of a table to the untrained eye, because you need to tell the table you want a border. If you add border="#" to the <table> tag, you will get a visible border. "1" gives you a thin border, I don't know what the maximum is, but 20-25 gives you a very sizable border, and this is likely the maximum you'll ever find a use for. In this case, the width is a number of pixels. Let's look at an example:
To illustrate the point about very wide borders, I present the following bit of evidence, with a border of "25":
Using Multiple Data CellsTo add more cells, simply repeat the <td> </td> pattern as many times as desired. <table border="1">
As you can see, when you use more than one cell, vertical lines will appear to separate the cells. This is propted by multiple uses of the <td> command. The width of a given cell, and in fact the entire table, is determined by the width of whatever you put into it. How to change cell size is covered on the next page about tables. Tables With More Than One RowCreating another row in your table is as simple as
creating a new cell. Simply close the first table row
using </tr> and the start a new row with another
<tr>. <table border="5">
Notice that there are now horizontal dividers along with the vertical ones, dividing each item into a visible cell. Notice the middle cell, which has no data entered in it. The table simply forms around this gap, but you must still use the tags, or no empty cell will be created. Using Header CellsAs mentioned before, data in a header cell will appear bold, and align itself to the center. Let's organize the above table with some headers. <table border="5">
More Table AttributesOkay. We have now created a few very basic tables, but they are anything other than perfect. The cells are odd sized and seem mismatched. The text is plain and boring; and the background is the same as the rest of the page, so the table tends to blend in, not call attention to itself as it should. The best way to improve upon what you have already learned in this section is to use table attributes. Some of these are covered in the next section. Click here to move on. | |||||||||||||||||||||||||||||||||||||||||||||