Yesterday, if you have noticed, my blog was down for a few hours. This was because I had problems with my Wordpress theme with sidebars getting messed up and found it hard to fix it up. I finally managed to debug this issue and found out it was all due to image over-sizing in my latest post. I googled a lot to find a fix for auto-resizing images in WordPress, but most of them were either blog theme specific or were controlling the image size before image upload.

how to resize images using css without losing the aspect ratio? - resize images

Then I found out a quick and easy way to resize images with CSS by keeping your image’s aspect ratio. This is very quick you can use it in less than 5 minutes, let’s proceed!

Lets say you want to show large images on your web page with maximum 200 pixels width, blog or forums just create the following css class into your styling css file:

.resize {
width: 200px;
height : auto;

.resize {
width: auto;
height : 300px;

Second class will resize the images by keeping height as 300 pixels. You can use the following classes in <IMG> tags like:

<img src=””  class=”resize” alt=”my photo”>

The above solution is always better than putting width and height attributes into the <IMG> tag. Hope it works out for you too

Was this article helpful?