the proposed solutions so far use vw which only work if you want the image to fill the entire page.
but there is a much cleaner solution that keep the image aspect ratio 9/16 in all size containers.
HTML:
...
<div class="image image-9-16"> <!-- replace image and image-9-16 with any name you like -->
<img src="..." />
</div>
...
CSS:
.image {
position: relative;
display: block;
width: calc(100% - 20px);
max-width: calc(100% - 20px);
height: auto;
max-height: 100%;
padding: 0;
margin: 0;
overflow: hidden;
}
.image::before {
display: block;
content: "";
}
.image, .image img {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
}
.image-9-16::before {
padding-top: 56.25%;
}
and that'll work no matter the width of the container holding the image with no need to place the image as a background-image... and now you can even add more aspect ratios if you want...
.image-1-1::before {
padding-top: 100%;
}
.image-3-4::before {
padding-top: 75%;
}
.image-9-21::before {
padding-top: 42.857143%;
}
...