Basic Table Tag Attributes

Attribute:

Applies to:

Purpose:

border

table
tr
td

Thickness of a visible border.

table: When the border attribute is missing, the table will not show a border, but the space for a border is there. border="0" makes the border vanish and the space for a border is gone, too.

cellpadding

table

White space between cell border and cell contents. Values are in pixels. Default is 1

cellspacing

table

White space between cells. If cells have borders, this creates a gap between the lines.

Values are in pixels. The default value is 2.

width

height

table

td

table: a number of pixels or a percentage of the window size. Height is rarely set on purpose. WYSIWYG programs may set height automatically.

td: a number of pixels or a percentage of the table size for width and of window size for height.

align

table
tr
td

table: Aligns whole table on the page. Value can be only left or right. Text will wrap around the table. Some browsers do not support this property for table.

To center a table you must use a trick. Surround the table with a centered division tag plus a deprecated CENTER tag:

<div align="center"><center>  </center></div>

tr or td: Aligns contents of cells. Value can be left , right , or center.

valign

table
tr
td

Aligns the contents of each cell vertically in the cell. Values can be top , middle , bottom, or baseline . Some browsers do not support this attribute for table.

rowspan

colspan



td

Sets how many rows or columns the cell should span. rowspan ="3" is like merging three cells in the same column. colspan ="2"  is like merging two cells in the same row.

bgcolor

 

table
tr
td

Sets the background color. Values are color numbers #rrggbb or color names.

background

table

td

Sets a background image. Value is the URL for the image. Netscape also accepts this attribute for tr.

bordercolor

bordercolorlight

bordercolordark

table
tr
td

Sets the color for border. The border attribute must be set in <table>for this to work in <tr> or <td>.
A border can use two colors to create a 3D effect. Netscape does not understand any of these attributes.