Table Background Color

This tutorial reveals how change the background colors in a table by adding an inline style sheet to Tables (table) and Table Data Cells (td).

Start with any HTML table such as this example with existing content:

<table width="300" height="90" cellspacing="1" cellpadding="5" border="0">
<tr>
<td colspan="3">#9932CC</td>
</tr>
<tr>
<td>#6B248E</td>
<td>#EFCFFE</td>
<td>#DF9FFE</td>
</tr>
</table>

Add the style attribute to the Table, Table Data Cell or both:

<table style="" width="300" height="90" cellspacing="1" cellpadding="5" border="0">
<tr>
<td style="" colspan="3">#9932CC</td>
</tr>
<tr>
<td style="">#6B248E</td>
<td style="">#EFCFFE</td>
<td style="">#DF9FFE</td>
</tr>
</table>

Add the CSS background-color: property:

<table style="background-color: " width="300" height="90" cellspacing="1" cellpadding="5" border="0">
<tr>
<td style="background-color: " colspan="3">#9932CC</td>
</tr>
<tr>
<td style="background-color: ">#6B248E</td>
<td style="background-color: ">#EFCFFE</td>
<td style="background-color: ">#DF9FFE</td>
</tr>
</table>

Add a hex color value to the background-color: property:

In this example, we are using colors from the DarkOrchid range.

<table style="background-color: #9932CC" width="300" height="90" cellspacing="1" cellpadding="5" border="0">
<tr>
<td style="background-color: #9932CC" colspan="3">#9932CC</td>
</tr>
<tr>
<td style="background-color: #6B248E">#6B248E</td>
<td style="background-color: #EFCFFE">#EFCFFE</td>
<td style="background-color: #DF9FFE">#DF9FFE</td>
</tr>
</table>

Output

#9932CC
#6B248E #EFCFFE #DF9FFE

Additional Formatting

Additional formatting can be achieved by adding more style rules. Pay special attention to the color: property and how it is used to change font colors.

<table style="background-color: #9932CC; font-weight: bold; font-size: 13px; text-align: center;" width="300" height="90" cellspacing="1" cellpadding="5" border="0">
<tr>
<td style="background-color: #9932CC; color: #FFFFFF" colspan="3">#9932CC</td>
</tr>
<tr>
<td style="background-color: #6B248E; color: #EFCFFE">#6B248E</td>
<td style="background-color: #EFCFFE; color: #6B248E">#EFCFFE</td>
<td style="background-color: #DF9FFE; color: #6B248E">#DF9FFE</td>
</tr>
</table>

Output

#9932CC
#6B248E #EFCFFE #DF9FFE

Tip

If many tables are to be styled the same, it is better to create an external style sheet and declare style rules with the class attribute. This way, if you ever want to change the colors, font sizes etc, you only need to change one file to make changes accross your entire web site.

100% Hand Coded Web Site
© 2008 Ed Zivkovic and html-color-names.com