HTML Background-color - Javatpoint

next → ← prevHTML Background-color

The <bgcolor> is the attribute to set the background color of an HTML element. This attribute is used with the following tags:

  • <body>
  • <table>
  • <marquee>
  • <td>
  • <th>
  • <tr>

Syntax

<"tag" bgcolor="Color_name|rgb number|Hex number">

Examples: The following examples use the <bgcolor> attribute in the different tags.

Example 1: Use the <bgcolor> attribute with the <body> tag

<!DOCTYPE html> <html> <head> <title> Example of Background color Attribute </title> </head> <body bgcolor="lightblue"> <!-- The attribute bgcolor use with the body tag to set the background of web page as lightblue --> <center> <h1> javaTpoint</h1> <br> <br> <center> <h2> Hyper Text Markup Language </h2> </center> </body> </html> Test it Now

Output:

HTML Background-color

Example 2: Use the <bgcolor> attribute with the <tr> tag

<!DOCTYPE html> <html> <head> <title> Example of Bgcolor Attribute </title> </head> <body bgcolor="red"> <!-- The attribute bgcolor use with the 'body' tag to set the background of web page as red --> <center> <h1> javaTpoint</h1> <br> <br> <center> <table> <!-- The attribute bgcolor use with the 'tr' tag to set the background of table rows by different colors --> <tr bgcolor="blue"> <td> Roll No. </td> <td> Name </td> </tr> <tr bgcolor="lightblue"> <td> 101 </td> <td> Abhay </td> </tr> <tr bgcolor="brown"> <td> 102 </td> <td> Chetan </td> </tr> <tr bgcolor="orange"> <td> 103 </td> <td> Manpreet </td> </tr> <tr bgcolor="yellow"> <td> 104 </td> <td> Rakesh </td> </tr> <tr bgcolor="lightgreen"> <td> 105 </td> <td> Sumit </td> </tr> </table> </center> </body> </html> Test it Now

Output:

HTML Background-color

Example 3: The following example use the <bgcolor> attribute with the <marquee> tag.

<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title> Example of Background color Attribute </title> </head> <body bgcolor="lightgreen"> <!-- The attribute bgcolor use with the body tag to set the background of web page as lightgreen --> <h1> <font color="blue"> <marquee bgcolor="orange"> <!-- The attribute bgcolor use with the marquee tag to set the background of marquee as orange --> javaTpoint </marquee> </font> </h1> </body> </html> Test it Now

Output:

HTML Background-color

Browser Support

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<bgcolor>YesYesYesYesYes
Next TopicHTML Date← prev next →

Từ khóa » Html Bgcolor Tag