Html – Set background image to cover according to viewport size

csshtml

With respect to the mentioned subject, I would like to know how to add code that will set the background image size to cover the window completely without the sides getting cut off.
I have tried using height and width auto,cover and 100% but none are working.

Any help is appreciated. Thank you!

Best Answer

Use the CSS background-size property.

If you want your background image to fill the area to the minimum width/height use:

background-size: cover;

If you want your background image to fill the area as large as possible but still show all your image use:

background-size: contain;