Software Development | Image Aspect Ratio

Image Aspect Ratio

Overview

The aspect ratio of an image is the proportional relationship between its width and its height. It is commonly expressed as two numbers separated by a colon, as in 16:9. For example, a 16:9 aspect ratio means that for every 16 pixels of width, there are 9 pixels of height.

When you work with images on the web, consider the aspect ratio of each image. In a responsive design, the image must scale properly as the viewport changes size. If the aspect ratio is not preserved, the image may become distorted or cropped in an undesirable way.

Issues

Aspect ratio is one of the checks in the Best Practices category of a Lighthouse audit.

Reference: 📑 Displays images with incorrect aspect ratio – Chrome for Developers

Here is an example Lighthouse report from DevTools where an image is displayed with an incorrect aspect ratio.

Screenshot of an aspect ratio issue from a Lighthouse audit
Lighthouse Best Practices audit flagging an incorrect aspect ratio

How to Fix

There are a few ways to fix an incorrect aspect ratio issue: