Open In App

HTML <tr> bgcolor Attribute

Last Updated : 12 Jan, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The HTML <tr> bgcolor Attribute is used to specify the background color of a table row. This attribute accepts color values such as color names, hex codes, or RGB values, allowing for easy customization of the background color for individual rows in an HTML table.

Note: It is not supported by HTML 5.

Syntax:

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

Attribute Values

Attribute Values

Description

color_name

It sets the background color by using the color name. For example “red”.

hex_number

It sets the background color by using the color hex code. For example “#0000ff”.

rgb_number

It sets the background color by using the RGB code. For example: “RGB(0, 153, 0)” .

Example: the implementation of <tr> bgcolor

html
<!DOCTYPE html>
<html>

<head>
    <title>HTML tr bgcolor Attribute</title>
    <style>
        body {
            text-align: center;
        }

        table {
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>

    <h2>
        HTML tr bgcolor Attribute
    </h2>

    <table width="500" border="1">
        <tr bgcolor="green">
            <th>Name</th>
            <th>Expenses</th>
        </tr>

        <tr bgcolor="yellow">
            <td>BITTU</td>
            <td>2500.00</td>
        </tr>

        <tr bgcolor="red">
            <td>RAKESH</td>
            <td>1400.00</td>
        </tr>
    </table>
</body>

</html>

Output:

Screenshot-2023-12-20-124909

Example: the implementation of <tr> bgcolor

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
      HTML tr bgcolor Attribute Example
      </title>
    <style>
        body {
            text-align: center;
        }

        table {
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>

    <h2>
        HTML tr bgcolor Attribute
    </h2>

    <table width="500" border="1">
        <tr bgcolor="orange">
            <th>Fruit</th>
            <th>Color</th>
        </tr>

        <tr bgcolor="yellow">
            <td>Banana</td>
            <td>Yellow</td>
        </tr>

        <tr bgcolor="pink">
            <td>Strawberry</td>
            <td>Red</td>
        </tr>

        <tr bgcolor="lightgreen">
            <td>Apple</td>
            <td>Green</td>
        </tr>
    </table>
</body>

</html>

Output:

Screenshot-2023-12-20-125103

Supported Browsers:

  • Google Chrome 1
  • Microsoft Edge 12
  • Firefox 1
  • Opera 12.1
  • Safari 1

Next Article

Similar Reads