Deprecated in HTML5. Do not use.

Why Table Bgcolor Is No Longer Valid Code (And What To Use Instead)

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more

Sharing is caring!

Attribute of
Create An HTML Table Quickly & Easily With Our Code Example
What does Why Table Bgcolor Is No Longer Valid Code (And What To Use Instead) do?
Was used to set the background color of an HTML table. This attribute has been deprecated. Use CSS to style tables.

Code Example

<table bgcolor="#ccccff">
  <tr><td>First column</td><td>Second column</td><td>Third column</td></tr>
  <tr><td>First column</td><td>Second column</td><td>Third column</td></tr>
  <tr><td>First column</td><td>Second column</td><td>Third column</td></tr>
</table>
First columnSecond columnThird column
First columnSecond columnThird column
First columnSecond columnThird column

Styling Table Background Colors

The bgcolor was once the correct way to specify the color to be applied to the background of a table. However, this attribute has been deprecated in favor or using CSS to style tables. The attribute does still work in most browsers and can accept color names, hex color codes, and rgb values. To set the background of a table with CSS, use the background-color property instead of the bgcolor HTML attribute.

<style> table.example-table {   background-color: #ccccff; } </style> <table class="example-table">   <tr><td>First column</td><td>Second column</td><td>Third column</td></tr>   <tr><td>First column</td><td>Second column</td><td>Third column</td></tr>   <tr><td>First column</td><td>Second column</td><td>Third column</td></tr> </table> 
table.example-table{background-color: #ccccff;}

First columnSecond columnThird column
First columnSecond columnThird column
First columnSecond columnThird column
Adam is a technical writer who specializes in developer documentation and tutorials.