Namecheap

Domain registration with free Whois privacy

Lesson 8: Tables

Making A Table

We’re talking here tables for holding data not the dinner table. Tables at one time were used in designing the layout of webpages. That's no longer the case but it's still worth the time to learn how to make them.

A table starts and ends with the table tag:

<table></table>

Between the opening and closing table tags go a couple of other tags, the tr tag:

<tr></tr>

It stands for “table row” and will make up one row across the table. Between the tr tags are found the td tags:

<td></td>

The td stands for “table data” it forms one box called a “cell” which contains content seen on the web page such as text or graphics.

Here’s how the table code is put together:

<table border="1">

<tr>
<td>Beagle</td>
<td>Chihuahua</td>
</tr>

<tr>
<td>Terrier</td>
<td>Collie</td>
</tr>

</table>

The border attribute in the table tag puts a border around the cells.

Take a close look at the code, this table will have 2 rows with 2 cells in each row. The stuff between the opening and closing td tags is what will be in each cell. Note that each row is finished off with the closing tr tag. Finally the table is finished by ending it with the closing table tag.

Result:

Beagle Chihuahua
Terrier Collie


Remember the style attribute from lesson 4? Put it into the opening td tags with a CSS padding command to add some space around the content of the cells:

<td style="padding:20px;">Beagle</td>

Result:

Beagle Chihuahua
Terrier Collie


We can make a table larger by putting the style attribute into the opening table tag and giving it a CSS width command:

<table border="1" style="width:300px;">

Result:

Beagle Chihuahua
Terrier Collie


Add the a CSS vertical-align command to a td tag and the content of that cell will start at the top of the cell:

<td style="vertical-align:top;">Chihuahua</td>

Result:

Beagle Chihuahua
Terrier Collie


Let's change the color of a cell with CSS background command:

<td style="background:aqua;">Terrier</td>

Result:

Beagle Chihuahua
Terrier Collie


And that folks is how a table is put together. By now you have all the tags you need to make a simple website, I hope you enjoyed the lessons enough to buy my book, HTML Made Easy with a free bonus CSS tutorial.

DID YOU KNOW...?
You can register a website address (called a domain in tech talk) even before you have a website. In fact the longer you wait the more difficult it will be to get one that isn't already taken. More Info

DID YOU KNOW...?
There is more to building a website than just making it. It also needs web hosting so that it can be seen on the internet. More Info

Easy Website Builder
Skip the tutorial and build your website or online store without learning any code Tell Me More
html tutorial
This tutorial is available in printable PDF format

Get Your Copy