HTML Tutorials‎ > ‎


In the next few minutes, I will show you how to do some simple stuff with tables!

Before I explain this table to you, here's the code I wrote to give me the table:

<table> <caption>Veggies!</caption>
<tr> <td>
Green Beans</td> <td>Corn</td> <td>Cucumber</td> </tr>
tr> <td>Lettuce</td> <td>Squash</td> <td>Celery</td> </tr>
tr> <td>Onion</td> <td>Asparagus</td> <td>Carrots</td> </tr>

Now, don't be worried by this. It looks strange, but look again. There's only 4 commands being used over & over.

Here's what we use:

<table> starts and ends the whole thing.

<caption> and </caption> places a caption over your table. The caption will be bolded and centered.

<tr> is used when you want a new Table Row to start. Notice that you need to end every table row with an </tr>. See that above?

<td> denotes Table Data. This goes in front of every piece of information you want in a cell. You need to end every one that you open with a </td>. See how it's done above.

And finally you finish with </table>.

Now, I will show you how to do more stuff with tables!

Here's the same table we worked with before but with more code added.

<table cellspacing="1" cellpadding="1" border="3"> <caption>Veggies!</caption>
tr> <td>Green Beans</td> <td>Corn</td> <td>Cucumber</td> </tr>
tr> <td>Lettuce</td> <td>Squash</td> <td>Celery</td> </tr>
tr> <td>Onion</td> <td>Asparagus</td> <td>Carrots</td> </tr>

 Green Beans Corn Cucumber
 Lettuce Squash Celery
 Onion Asparagus Carrots

Now, you're using the 3 new commands listed below : 

cellspacing (all one word) gives the amount of space between cells.
cellpadding (all one word) gives the amount of space (or padding) between the cell border and the cell contents. Note the cell border walls tend to fill out. A higher number fills out more. Try a few different settings to see what looks best.
border tells the table how large the border should be. This is in terms of pixels. Try different numbers. border="0" gets rid of the borders altogether.

Now, we'll go into coloring your tables.

For starters, let's take a look at a regular table:

<table border="0"> <tr><td> </td></tr></table>

Now, if you want the background color of your whole table to be the same,  you'd put the code within the start tag, like so:

<table bgcolor="#FFFFFF">

Same thing with a background image:

<table background="image.gif">

Now, if you just want to color one cell, you'd do this:

<table border="0"> <tr><td bgcolor="#FFFFFF"></td></tr></table>

Or, for a one celled background image:

<td background="image.gif">

With the td attributes, you can have every cell be a different color or background image.

I hope this tables tutorial has been helpful. Happy table building!