Introduction

In HTML, the bgcolor attribute sets the background color of a HTML element. The bgcolor attribute can be used with the HTML tags like

<body>, <table>, <marquee>, <td>, <tr>, <th>.

SYNTAX

CSS:

<body style="background-color:#787878A">

BGCOLOR:

<"tag" bgcolor="rgb/hex/color_name">

· tag - you can use any HTML tag like <body> , <p>, <button>, etc.

· rgb/hex/color_name - These are attribute values, there are different ways to use colors but can use only one at a time.

ATTRIBUTES

Attribute value

Description

rgb_number

A rgb code determines the background color (like "rgb(255,225,0)")

hex_number

Hex code specifies the color of the background (like "#ff0ff0")

color_name

This color specifies the background color (like "blue")

EXAMPLES:

Set the bg color of the body to blue.

<!DOCTYPE html>

<html>

<body bgcolor="blue">

<h1>BOARD INFINITY</h1>

</body>

</html>

OUTPUT:

HTML bgcolor Attribute by specifying the text as blue & background as pink color

<!DOCTYPE html>

<html>

<body text="blue" bgcolor="pink">

<h1>BOARD INFINITY</h1>

</body>

</html>

OUTPUT:

Using bgcolor with table

<!DOCTYPE html>

<html>

<body bgcolor="lightblue">

<h1>Using bgcolor with tables</h1>

<table border="1" bgcolor="yellow">

<caption>

BOARD INFINITY </caption>

<tr>

<th>Name</th>

<th>Subject</th>

<th>Marks</th>

</tr>

<tr>

<td>Aman</td>

<td>Math</td>

<td>88</td>

</tr>

<tr>

<td>Shanti</td>

<td>Science</td>

<td>95</td>

</tr>

</table>

</body>

</html>

write your code here: Coding Playground

OUTPUT