CSS Properties: How to set a background-image for the body element?
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
Yes | Yes | Yes | Yes | No |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
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
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics