Science, Tech, Math › Computer Science Change the Background Color of an HTML Table Share Flipboard Email Print Science, Tech, Math PHP Programming Perl Python Java Programming Javascript Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Jennifer Kyrnin Jennifer Kyrnin Writer University of California University of Washington Jennifer Kyrnin is a professional web developer who assists others in learning web design, HTML, CSS, and XML. Learn about our Editorial Process Updated on January 31, 2021 Reviewed by Ryan Perian Reviewed by Ryan Perian Western Governors University Ryan Perian is a certified IT specialist who holds numerous IT certifications and has 12+ years' experience working in the IT industry support and management positions. Learn about our Editorial Process What to Know Easiest: add the style property background-color to the table, row, or cell tag.Next easiest: use the attribute bgcolor. This article explains the methods for changing the background colors of parts of a table on a website. The older method used the attribute bgcolor to change the background color of a table. It could also be used to change the color of a table row or a table cell. But the bgcolor attribute has been deprecated in favor of style sheets, so it's not the optimal way to manipulate a table's background color. The better way to change the background color is to add the style property background-color to the table, row, or cell tag. This example changes the background color of an entire table: To change the color of a single row, insert the background-color property in thetag: You can change the color of a single cell by adding the attribute to thetag: You can also apply background colors to table heads, or the Change Background Color Using Style Sheets However, it's better to avoid using the background-color attribute in favor of a correctly formatted style sheet. For example, you can set the styles in a style sheet at the HEAD of your HTML document or set them in an external style sheet. Changes like these in the HEAD or an external style sheet might appear like these for tables, rows, and cells: table { background-color: #ff0000; }tr { background-color: yellow; }td { background-color: #000; } Setting Column Background Color The best way to set the background color for a column is to create a style class and then assign it to the column's cells. Creating a class allows you to assign that class to the cells in a specific column using one attribute. The CSS: td.ColColor { background-color: blue; } The HTML: cell 1cell 2cell 1cell 2 One significant advantage of controlling background colors through a style sheet is that you can change your color choice later. Rather than going through the HTML document and making the change to every single cell, you can make a single change to the color choice in the CSS that will immediately be applied to every instance where the class="ColColor" syntax appears. Although interspersing CSS into your HTML, or calling a separate CSS file, adds a bit of administrative overhead beyond just modifying an HTML attribute, you'll find that relying on CSS reduces errors, speeds up development, and improves the portability of your document. Cite this Article Format mla apa chicago Your Citation Kyrnin, Jennifer. "Change the Background Color of an HTML Table." ThoughtCo, Sep. 30, 2021, thoughtco.com/change-table-background-color-3469869. Kyrnin, Jennifer. (2021, September 30). Change the Background Color of an HTML Table. Retrieved from https://www.thoughtco.com/change-table-background-color-3469869 Kyrnin, Jennifer. "Change the Background Color of an HTML Table." ThoughtCo. https://www.thoughtco.com/change-table-background-color-3469869 (accessed May 28, 2023). copy citation By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookies Settings Accept All Cookies