HTML <td> bgcolor Attribute

Last Updated : 22 May, 2026

The bgcolor attribute in the <td> tag sets the background color of a table cell to improve visibility and presentation.

  • Used to apply background color to a table cell.
  • Accepts color names, HEX, or RGB values.
  • Works with the <td> element.

Note: The bgcolor attribute is deprecated in HTML5, so use CSS (background-color) instead.

Syntax

<td bgcolor= "color_name | hex_number | rgb_number">

Attribute Values

  • color_name: Sets the background color using a color name (e.g., "red").
  • hex_number: Sets the background color using a HEX code (e.g., "#0000ff").
  • rgb_number: Sets the background color using an RGB value (e.g., "rgb(0, 153, 0)").

Example 1:

html
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>

<head>
    <title>HTML <td> bgcolor Attribute</title>
</head>

<body>
    <h1>GeeksforGeeks</h1>

    <h2>HTML td bgcolor Attribute</h2>

<!--Driver Code Ends-->

    <table width="500" border="1">
        <tr>
            <th>NAME</th>
            <th>AGE</th>
            <th>BRANCH</th>
        </tr>

        <tr>
            <td bgcolor="green">BITTU</td>
            <td bgcolor="red">22</td>
            <td bgcolor="yellow">CSE</td>
        </tr>

        <tr>
            <td bgcolor="yellow">RAKESH</td>
            <td bgcolor="green">25</td>
            <td bgcolor="red">EC</td>
        </tr>
    </table>

<!--Driver Code Starts-->
</body>

</html>
<!--Driver Code Ends-->

Example 2: 

HTML
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>

<body>
    <center>
        <h1 style="color: green;">
          GeeksforGeeks
          </h1>
        <h3 style="color:darkcyan;font-weight:bold;">
            Table Cell Background Color
        </h3>
<!--Driver Code Ends-->

        <table border="1">
            <tr>
                <td bgcolor="lightblue">
                  Cell 1
                  </td>
                <td bgcolor="lightcoral">
                  Cell 2
                  </td>
                <td bgcolor="lightgreen">
                  Cell 3
                  </td>
            </tr>
        </table>

<!--Driver Code Starts-->
    </center>
</body>

</html>
<!--Driver Code Ends-->
Comment