How to center a background image within a div with CSS?

Spread the love

Sometimes, we want to center a background image within a div with CSS.

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

How to center a background image within a div with CSS?

To center a background image within a div with CSS, we use center.

For instance, we write

#doit {
  background: url(url) no-repeat center;
}

to set theg background to the background image URL.

And we use center to center it.

Conclusion

To center a background image within a div with CSS, we use center.

Leave a Reply

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