Html Image Keep Aspect Ratio. The following example will create an aspect ratio of 1 1 the height and width is always equal. To preserve the aspect ratio all you need to do is set the height and width css properties as shown.

Add a percentage value for padding top to maintain the aspect ratio of the div. Though as dlamblin points out just changing one value should preserve the aspect ratio. Control image aspect ratios with css3.
Control image aspect ratios with css3.
Html keep maintain aspect ratio when resizing image how to maintain aspect ratio using html img tag 5 don t set height and width. Resizing and letterboxing the image slightly to conserve the aspect ratio is a much more elegant solution than squashing and stretching an image to fit. To preserve the aspect ratio all you need to do is set the height and width css properties as shown. Use one or the other and the correct aspect ratio will be maintained.