How to display the background color of an element in HTML?

HTMLWeb DevelopmentFront End Technology

Use the bgcolor attribute in HTML to display the background color of an element. It is used to control the background of an HTML element, specifically page body and table backgrounds.

Note − This attribute is not supported in HTML5.

Example

You can try to run the following code to learn how to implement bgcolor attribute in HTML −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML Background Colors</title>
   </head>
   <body>
      <!-- Format 1 - Use color name -->
      <table bgcolor = "yellow" width = "100%">
         <tr>
            <td>
               This background is yellow
            </td>
         </tr>
      </table>

      <!-- Format 2 - Use hex value -->
      <table bgcolor = "#6666FF" width = "100%">
         <tr>
            <td>
               This background is sky blue
            </td>
         </tr>
      </table>

      <!-- Format 3 - Use color value in RGB terms -->
      <table bgcolor = "rgb(255,0,255)" width = "100%">
         <tr>
            <td>
               This background is green
            </td>
         </tr>
      </table>
   </body>
</html>
raja
Published on 13-Mar-2018 11:47:01
Advertisements