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
- 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 column | Second column | Third column |
First column | Second column | Third column |
First column | Second column | Third 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 column | Second column | Third column |
First column | Second column | Third column |
First column | Second column | Third column |