How to force image resize and keep aspect ratio?

img {
  display: block;
  max-width:230px;
  max-height:95px;
  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="https://i.stack.imgur.com/aEEkn.png">

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

Leave a Comment

tech