Idocs Guide to HTML

Attribute for <TR ...>
BGCOLOR = color expression

BGCOLOR sets the background color for a table row. BGCOLOR should only be used if you already know that the background color is compatible with the font color of the page. Otherwise it's easier and more reliable to use styles. See Table Backgrounds: Rows.

For example, this code sets the background color of the first row to a light brown:

this code produces this
<TABLE CELLPADDING=8>
<TR BGCOLOR="#CCCC99">
   <TD>lemons</TD>
   <TD>grapefruit</TD>
   </TR>
<TR>
   <TD>bananas</TD>
   <TD>pineapple</TD>
   </TR>
</TABLE>
lemons grapefruit
bananas pineapple

MSIE and Netscape render row background colors differently if CELLSPACING is set to zero. MSIE fills the entire row with the color, but Netscape leaves spaces between the cells. Unfortunately there's no good workaround for the Netscape problem. Usually the best thing to do is to hide the problem by adding borders to the table:

this code produces this
<TABLE CELLPADDING=8 BORDER=2>
<TR BGCOLOR="#CCCC99">
   <TD>lemons</TD>
   <TD>grapefruit</TD>
   </TR>
<TR>
   <TD>bananas</TD>
   <TD>pineapple</TD>
   </TR>
</TABLE>
lemons grapefruit
bananas pineapple

Copyright 1997-2002 Idocs Inc. Content in this guide is offered freely to the public under the terms of the Open Content License and the Open Publication License. Contents may be redistributed or republished freely under these terms so long as credit to the original creator and contributors is maintained.