Return to my Computer pages
Go to my home page


Beginner's HTML Guide IV - Tables

© Copyright 1998, Jim Loy

This is a table, in HTML:

red blue green
red red violet yellow
blue blue blue-green
green green

This is pretty simple to do. Here's how you enter it into your HTML file:

<TABLE BORDER>
  <TR>
    <TD></TD>
    <TD><B>red</B></TD>
    <TD><B>blue</B></TD>
    <TD><B>green</B></TD>
  </TR>
  <TR>
    <TD><B>red</B></TD>
    <TD>red</TD>
    <TD>violet</TD>
    <TD>yellow</TD>
  </TR>
  <TR>
    <TD><B>blue</B></TD>
    <TD></TD>
    <TD>blue</TD>
    <TD>blue-green</TD>
  </TR>
  <TR>
    <TD><B>green</B></TD>
    <TD></TD>
    <TD></TD>
    <TD>green</TD>
  </TR>
</TABLE>

I started with the <TABLE> tag. But, I wanted the borders to be visible, so I used the <TABLE BORDER> option. You can provide much more formatting information. But, I am just showing the basics. The table ends with the <

TABLE> tag. Within the table are table rows, between the <TR>...</TR> tags. Everything between these tags is part of the same row. The elements, in each row, are table cells (made up of text, lists, tables...), which are placed between <TD>...</TD>. Notice that I made some of the text bold, by surrounding it with <B></B>.

A larger table can look confusing. So, it is much easier to create one with a wysiwyg html editor.

Note that none of the tags need be capitalized. But, it looks clearer, to me, when I do that.


This two-column text is a handy use for tables. I created a table made up of only two cells, one row and two columns. This is how I defined it, originally:

<TABLE>
<TR>
<TD>This two-column text is a...</TD>
<TD>First, I defined...</TD>
</TR>
</TABLE>

The second column is merely the second cell of the 1x2 table.

Formatting is a little difficult to predict, unless you do actually specify the formatting.

First, I defined the width of the table to be 100% of the user's window, by modifying the <TABLE> tag: <TABLE width=100%>. Then I made each cell in the only row 50% of the user's window, by modifying the two <TD> tags: <TD width=50%>

Then, I wanted to make sure that the top line of each column lined up with each other. So, I modified the <TR> tag: <TR valign=top>.

Then I wanted a bigger gap between columns. So, I again modified the <TABLE> tag: <TABLE width=100% cellpadding=10>

This is how it ended up:

<TABLE width=100% cellpadding=10>
<TR valign=top>
<TD width=50%>Here is a...</TD>
<TD width=50%>First, I defined...</TD>
</TR>
</TABLE>

You should experiment with formatting, to see how different options turn out.

> Note that the </TR> tag is not necessary.


Basic format:

<TABLE>
<TR><TH>
<TR><TD>
</TABLE>

Options:

<TABLE> (table must end with </TABLE> tag)

<TR> table row (</TR> not necessary)

<TD> table data (can use all of the attributes of <TR> as well as these, below)

<CAPTION>...</CAPTION> table caption (can ALIGN=TOP or BOTTOM).

<TH> table heading (same as <TD> except that the contents may end up centered and bold)

> None of this need be in capital letters. The tags </TD> or </TH> are not necessary unless there is a conflict (tables within tables).


Return to my Computer pages
Go to my home page