Home » Script and Codes » Add CSS Background Image or Color

Add CSS Background Image or Color

How to add CSS background image or color?

Add CSS Background Image or Color: The background-color property specifies the background color of an element.

1. CSS Background Color Code:

<style>
body {
  background-color: lightblue;
}
</style>

Example:

<!DOCTYPE html>
<html>
<head>
<style>
body {
  background-color: lightblue;
}
</style>
</head>
<body>

<h1>Hello World!</h1>

<p>This page has a light blue background color!</p>

</body>
</html>

Result:

2. CSS Background Image Code

The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element.

<style>
body {
  background-image: url("https://domain.com/paper.gif");
}
</style>

Example:

<!DOCTYPE html>
<html>
<head>
<style>
body {
  background-image: url("https://domain.com/paper.gif");
}
</style>
</head>
<body>

<h1>Hello World!</h1>

<p>This page has an image as the background!</p>

</body>
</html>

Result:

Scroll to Top