Blog
It's a Wonderful Life
How to maintain aspect ratio using HTML IMG tag
-
don’t set
heightANDwidth, use one or the other and the correct aspect ratio will be maintained..widthSet { max-width: 64px; } .heightSet { max-height: 64px; }<img src="http://placehold.it/200x250" width="64" /> <img src="http://placehold.it/200x250" height="64" /> <img src="http://placehold.it/200x250" class="widthSet" /> <img src="http://placehold.it/200x250" class="heightSet" /> -
use
object-fitelementimg { width: 100%; height: 100%; object-fit: contain; } -
given the circumstances, if possible, use
backgroundelement instead