How to auto-resize an image to fit a div container with CSS?

Spread the love

Sometimes, we want to auto-resize an image to fit a div container with CSS.

In this article, we’ll look at how to auto-resize an image to fit a div container with CSS.

How to auto-resize an image to fit a div container with CSS?

To auto-resize an image to fit a div container with CSS, we can use the object-fit CSS property.

For instance, we write

<img style="height: 100%; width: 100%; object-fit: contain" />

to use object-fit: contain to auto resize the image to fit its container.

Conclusion

To auto-resize an image to fit a div container with CSS, we can use the object-fit CSS property.

Leave a Reply

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