View video tutorial

CSS Background Image

CSS

The background-image property specifies an image to use as an element's background.

CSS background-image property.

The background-image property is used to set an image to the background of an element.

Example

<div style="background-image:url('resources/images/mountain.jpg');border-radius: 5px; padding:10px;">
  <h1>CSS background-image Example</h1>
  <p>The CSS background property is used to set the background effect on the element.</p>
  <p>The following are CSS background properties that affect HTML elements.</p>
</div>
Try it Now »

Click on the "Try it Now" button to see how it works.


Sample Code

Copy each file contents and paste it to your own project and run to see the final output

Example

<body style="background-image:url('resources/images/mountain.jpg');">
  <div style="border-radius: 5px; padding:10px;">
    <h1>CSS background-image Example</h1>
    <p>The CSS background property is used to set the background effect on the element.</p>
    <p>The following are CSS background properties that affect HTML elements.</p>
  </div>
</body>
Try it Now »

Click on the "Try it Now" button to see how it works.

Note: By default, the image is repeated if it cannot cover the entire element.