How to add a background image to a div element with CSS?

Spread the love

Sometimes, we want to add a background image to a div element with CSS.

In this article, we’ll look at how to add a background image to a div element with CSS.

How to add a background image to a div element with CSS?

To add a background image to a div element with CSS, we set the background-image property.

For instance, we write

<div class="bgimg">div with background</div>

to add a div.

Then we write

.bgimg {
  background-image: url("../images/divbg.png");
}

to set the background-image property to the URL of the background image.

Conclusion

To add a background image to a div element with CSS, we set the background-image property.

Leave a Reply

Your email address will not be published. Required fields are marked *