html css keep image aspect-ratio code example
Example 1: preserve aspect ratio image css
/* Simply add width without height,
aspect ratio will be maintained
and height will be calculated accordingly*/
img {
width: 100px;
}
Example 2: html image keep aspect ratio
Don't set height AND width. Use one or the other and the correct aspect ratio will be maintained.