Table elements support the same bgcolor attribute that can be applied to an entire Web page. This attribute can be added to <table>, <tr>, <td>, or <th>, tags as follows:
HTML tags | Comments |
---|---|
<table bgcolor="color"> <tr bgcolor="color"> <td bgcolor="color"> <th bgcolor="color"> |
applying background color to all table cells applying background color to the entire row of cells applying background color to a particular cell applying background color to a particular cell |
Here color is either HTML color name or its RGB encoding.
Usage of these attributes is demonstrated on the following examples.
Setting background color of all table cells:
Layout | HTML tags | ||||
---|---|---|---|---|---|
|
<table border="1" bgcolor="orange"> <tr><td>cell 1</td> <td>cell 2</td></tr> <tr><td colspan="2">cell 3</td></tr> </table> |
Setting background color of the first row of cells:
Layout | HTML tags | ||||
---|---|---|---|---|---|
|
<table border="1"> <tr bgcolor="orange"><td>cell 1</td> <td>cell 2</td></tr> <tr><td colspan="2">cell 3</td></tr> </table> |
Setting background color of the first cell only:
Layout | HTML tags | ||||
---|---|---|---|---|---|
|
<table border="1"> <tr><td bgcolor="orange">cell 1</td> <td>cell 2</td></tr> <tr><td colspan="2">cell 3</td></tr> </table> |