Search code examples
javascriptcssresponsive-designdimension

Maintaining the aspect ratio of Image using CSS or jQuery?


I have images which dimension is (900x512). As I am going to make it responsive so images need to adjust within that screen width maintaining aspect ratio!!


Solution

  • Use:

    <img src="..." style="width: 100%; height: auto;" />
    

    this will keep the aspect-ratio. height: auto will make sure the height is not set elsewhere (as mentioned by cale_b)