However when I change the Css code to, max-height: 150px; max-width: 200px; width: 120px; height: 120px; I get images that are all the same size but the aspect ratio is stretched ruining the images. Auto resize an image (img) to fit into a smaller Div can be achieved through simple CSS or CSS3. To maintain the aspect ratio of images in CSS, the easiest way is to manually set the width of the image and the height to auto; Or vice-versa, set the height of the image, and the width to auto. In this snippet, we will learn how to zoom/scale an element, particularly images and background images on hover with pure CSS.This kind of effect is prominently used in galleries, selling products and portfolio-type cases where the design has a purpose of showing both visual and informational details. In this tutorial I will explain both CSS and CSS3 ways using simple html example.Add max-width,max-height CSS as 100% for img tag,then image will be auto resized.Use CSS3 object-fit:contain to resize img to fit into div. With CSS like img { width: 100%; height: auto; }, IE will auto-scale the image area to keep the width:height aspect ratio constant, but it won’t scale the actual drawing to match the scale of the image dimensions. You can also resize an image through CSS, as shown in the examples below. Its result is a data type.. Using this option, limits the images that use that CSS. Here it’s shown at half its size, 600px by 337px: So you have placed an image on your webpage and decided to resize it a little… But a slight problem happened and the image goes out-of-proportions. img.resize { width:200px; height:40px; } img.resize { max-width:50%; max-height:50%; } In the first example, the actual size in pixels is specified for width and height. This scaling transformation is characterized by a two-dimensional vector. The rendering engine has all the data: size of the container and size of the image. Eg. The following image’s original width is 1200px and height is 674px. CSS Rounded Corners CSS Border Images CSS Backgrounds CSS Colors CSS Gradients. Resize with CSS. none: The image is not resized at all, and the original image size fills the given area. allowing me to keep the aspect ratio. Instead of assigning an absolute width value via a HTML attribute in the tag of an image, assign the CSS rule max-width that targets the image as a percentage relative width value like so: img {max-width:100%} What this will do is make the image display 100% of its size within its parent element available width space. I am looking for a CSS-only solution. is there not a way to resize the image container and not the image instead? While you cannot “resize” images in CSS3, you can make them appear to be resized in the browser using media queries and the principles of responsive design. ... scale-down - The content is sized as if none or contain were specified (would result in a smaller concrete object size) The following example demonstrates all the possible values of the object-fit property: Correct. The scale() CSS function defines a transformation that resizes an element on the 2D plane. scale-down: The smaller of either contain or none. Example. How to Scale Images and Background Images on Hover. If you want your image to be scaled differently (or add/override certain styles for more responsivenss) in different devices you need to use CSS media queries. The image will fill its given area, even if it means losing its aspect ratio. Because the amount of scaling is defined by a vector, it can resize the horizontal and vertical dimensions at different scales.