Home > Web Front-end > HTML Tutorial > How to display the background color of an element in HTML?

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

WBOY
Release: 2023-08-27 19:57:19
forward
755 people have browsed it

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

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

Note - HTML5 does not support this attribute.

Example

You can try running the following code to understand how to implement the 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>
Copy after login

The above is the detailed content of How to display the background color of an element in HTML?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template