

While the same image with a 16:9 ratio would look as follows: Note: The above image is viewed on LambdaTest. Represented by a colon (as A: B), the aspect ratio determines how your image (or any other shape) would appear on the web page.įor an aspect ratio of 1:1, the image would appear as a square: The aspect ratio of an image is the ratio of its width to its height. CSS Aspect Ratio with Width and Height Attributes.CSS Aspect Ratio with Predefined Height.This post will guide you along with this new property and introduce various implementations in different scenarios and how aspect-ratio reacts in those situations.

Thankfully, CSS developers have introduced a new property called aspect-ratio that can take care of a lot of such stuff. A small change in a single element’s dimensions can cause a ripple effect on the complete web page. With the recent trends in web development, there has been an increase in the complexities of the project. It had become frustrating to waste a lot of time just to adjust an element to look perfectly on multiple devices with time. The aspect-ratio is always a measured property that needs adjustments and careful scrutiny. The aspect-ratio is extremely important given the effect a UI has on the end-user. What if I could increase that image width to 30px more? Or maybe 20%? Deciding the final width at the end now requires us to adjust the height as well! What if multiple elements were to be adjusted according to the new values like in a CSS-grid or subgrid structure? This is where the CSS aspect ratio comes into play. Being web developers, we are hardly satisfied by the dimensions of our elements on the web page.
