Tables

Element of Table

HTML Code

Example

Basic table

<TABLE>
<TR><TD>Item 1</TD></TR>
<TR><TD>Item 2</TD></TR>
<TR><TD>Item 3</TD></TR>
</TABLE>

Item1

Item 2

Item 3


Adding a border

<TABLE border=1>
<TR><TD>Item 1 </TD></TR>
<TR><TD>Item 2 </TD></TR>
<TR><TD>Item 3 </TD></TR>
</TABLE>

Item 1

Item 2

Item 3


Multiple Rows and Columns

<TABLE border=1>
<TR><TD>Row 1, Item 1</TD></TR>
<TR>
<TD>Row 2, Item 1 </TD>
<TD>Row 2, Item 2 </TD>
</TR>
<TR><TD>Row 3 Item 1 </TD></TR>
</TABLE>

Spanning Cells

<TABLE border=1>
<TR><TD colspan=2>Row 1, Item 1, 2 columns</TD></TR>
<TR>
<TD rowspan=2>Row 2, Item 1, 2 rows </TD>
<TD>Row 2, Item 2 </TD>
</TR>
<TR><TD >Row 3, Item 1, </TD></TR>
</TABLE>

 

Setting alignment within a cell

<TABLE border=1>
<TR>
<TD colspan=2 align="middle">Row 1, Item 1</TD>
</TR>
<TR>
<TD>Row 2, Item 1 </TD>
<TD>Row 2, Item 2 </TD>
</TR>
</TABLE>

 

Adding a Heading

<TABLE border=1>
<TR>
<TH colspan=2 align="middle">Heading</TH>
</TR>
<TR>
<TD>Row 2, Item 1 </TD>
<TD>Row 2, Item 2 </TD>
</TR>
</TABLE>

 


Table Elements
Element
Description
<TABLE> ... </TABLE> defines a table in HTML. If the BORDER attribute is present, your browser displays the table with a border.
<TR> ... </TR> specifies a table row within a table. You may define default attributes for the entire row: ALIGN (LEFT, CENTER, RIGHT) and/or VALIGN (TOP, MIDDLE, BOTTOM). See Table Attributes at the end of this table for more information.
<TH> ... </TH> defines a table header cell. By default the text in this cell is bold and centered. Table header cells may contain other attributes to determine the characteristics of the cell and/or its contents. See Table Attributes at the end of this table for more information.
<TD> ... </TD> defines a table data cell. By default the text in this cell is aligned left and centered vertically. Table data cells may contain other attributes to determine the characteristics of the cell and/or its contents. See Table Attributes at the end of this table for more information.

Table Attributes
Attribute
Description
ALIGN (LEFT, CENTER, RIGHT) Horizontal alignment of a cell.
VALIGN (TOP, MIDDLE, BOTTOM) Vertical alignment of a cell.
COLSPAN The number of columns a cell spans.
ROWSPAN The number of rows a cell spans.
NOWRAP Turn off word wrapping within a cell.

Back to tutorials