Body Background Image and Color in HTML
Backgrounds and Colors
In this lesson, we will learn how to set body background image and color in HTML.
Setting Body Background Color in HTML
To set the background color of the body tag, you need to use the bgcolor attribute. The bgcolor attribute sets the background color of the body to the specified color. You can use any valid color name or hex code. For example:
Example
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Body Background Color Example</title>
</head>
<body bgcolor="yellow">
<p>This is a sample paragraph 1</p>
<p>This is a sample paragraph 2</p>
<p>This is a sample paragraph 3</p>
<p>This is a sample paragraph 4</p>
<p>This is a sample paragraph 5</p>
</body>
</html>
Setting Body Background Image in HTML
To set an image as the background of the body tag, you need to use the background attribute. The background attribute sets the background image of the body to the specified image. For example:
Example
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Body Background Image Example</title>
</head>
<body background="https://www.dremendo.com/html-tutorial/images/tile-image.jpg">
<p>This is a sample paragraph 1</p>
<p>This is a sample paragraph 2</p>
<p>This is a sample paragraph 3</p>
<p>This is a sample paragraph 4</p>
<p>This is a sample paragraph 5</p>
</body>
</html>
Note: If the background image is small, it will fill the entire body by repeating itself.