w3resource

CSS Properties: How to set a background-image for the body element?

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html>
<html>
<head>
<style>/* CSS style start*/
body  {
    background-image: url("https://www.w3resource.com/images/w3resource-logo.png"); /* Set the background image of the body */
    background-color: #6699CC; /* Set the background color of the body */
}
</style>
</head>
<body>
<h1>w3resource background image</h1><!-- Display a heading -->
</body>
</html>

Explanation:

  • The CSS code sets the background image of the body to the specified URL.
  • It also sets the background color of the body to a shade of blue (#6699CC).
  • The HTML code contains a heading element (<h1>) that displays the text "w3resource background image".

Live Demo:

See the Pen background-image-answer by w3resource (@w3resource) on CodePen.


See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes No

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/html-css-exercise/css-properties/background-image-answer.php