Languages
[Edit]
EN

CSS - set image as element background

0 points
Created by:
Evania
314

In this article, we would like to show you how to set image as element background using CSS.

Quick solution:

body {
  background-image: url("example-image.jpg");
}

 

Practical example

In this example, we add a background image to the body element using background-image property.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    body { 
      height: 200px;
      
      /* required */
      background-image: url("https://dirask.com/static/bucket/1631892737905-aBQOGgdQPg--background-h500-w2250.jpg");
    }

    div {
      padding: 10px;
      color: white;
    }

  </style>
</head>
<body>
  <div>Example text...</div>
</body>
</html>
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join