GuideML: TABLE Tag
Created | Updated May 2, 2003
Tables are used to lay out content in tabular format. The <TABLE> tag is the main construct, but the complete list of tags covered here comprises:
- <TABLE>
- <TD>
- <TH>
- <TR>
- <CAPTION>
Syntax and Usage
Optional attributes are shown in italics, and the vertical bar character | denotes a choice, so LEFT|CENTER|RIGHT means one of LEFT, CENTER or RIGHT.
<TABLE BORDER="1">
<CAPTION>Caption</CAPTION>
<TR ALIGN="LEFT|CENTER|RIGHT" VALIGN="TOP|MIDDLE|BOTTOM">
<TD|TH ALIGN="LEFT|CENTER|RIGHT" VALIGN="TOP|MIDDLE|BOTTOM" COLSPAN="n" ROWSPAN="n">...cell contents...</TD|TH>
...more cells...
</TR>
...more rows...
</TABLE>
Here's how to create a table:
Start a table with a <TABLE> tag, and end it with a corresponding </TABLE> tag; these act like a paragraph tag pair, so don't put a table inside a paragraph, blockquote and so on.
Rows are created one after the other, with each row enclosed by a <TR>...</TR> pair. For each row we have to create each cell in that row, from left to right, with the contents of each cell being enclosed by a <TD>...</TD> pair (or <TH>...</TH> for a header cell, which is just like a normal row but is displayed as a header row, usually in bold).
If you want a cell to be blank, use as the cell's contents. is the entity for a non-breaking space, and should be used for empty cells: never create an empty cell with <TD></TD> as this might cause some problems with some browsers (notably Netscape).
Putting BORDER="1" after the TABLE tag will put a border round each table cell. This is useful if you think you're going to have multiple-line cells and things might not line up obviously.
The ALIGN and VALIGN attributes control how the text is aligned horizontally and vertically within cells. If included with the <TR> tag they control that whole row, whereas putting them with individual cells controls just those cells' alignments.
The COLSPAN and ROWSPAN attributes make cells span multiple columns and rows, the number being given by the argument. The best way to discover how these work is by experimentation.
Known Issues
Both Netscape and Internet Explorer reset the font in table cells to the default for that page, and ignore the current settings. This means that the font inside table cells will probably revert to Times. Changing fonts, however, is not possible in Approved GuideML, so this problem will be fixed at the parser end.
Example One
Rainfall | Sunlight | |
---|---|---|
Britain | 30m | Zero |
Everywhere Else | 0m | 12 hrs |
<TABLE>
<TR><TH> </TH><TH>Rainfall</TH><TH>Sunlight</TH></TR>
<TR><TD>Britain</TD><TD>30m</TD><TD>Zero</TD></TR>
<TR><TD>Everywhere Else</TD><TD>0m</TD><TD>12 hrs</TD></TR>
</TABLE>
Example Two
A Table of Meaningless Words | |||
---|---|---|---|
Multiple Line | Top | Middle | Bottom |
To the right | Centre |
<TABLE BORDER="1">
<CAPTION>The caption goes here</CAPTION>
<TR><TH COLSPAN="4">A Table of Meaningless Words</TH></TR>
<TR><TD>Multiple<BR/>Line</TD><TD VALIGN="TOP">Top</TD><TD VALIGN="MIDDLE">Middle</TD><TD VALIGN="BOTTOM">Bottom</TD></TR>
<TR><TD COLSPAN="3" ALIGN="RIGHT">To the right</TD><TD COLSPAN="1" ALIGN="CENTER">Centre</TD></TR>
</TABLE>