How to force image resize and keep aspect ratio?

img {
  display: block;
  width: auto;
  height: auto;
<p>This image is originally 400x400 pixels, but should get resized by the CSS:</p>
<img width="400" height="400" src="">

This will make image shrink if it’s too big for specified area (as downside, it will not enlarge image).

Leave a Comment