# "Displays images with incorrect aspect ratio": how to fix it

**Audit ID:** `image-aspect-ratio` · **Category:** Best Practices

<!--QA-->
> **Quick answer:** Lighthouse flags "Displays images with incorrect aspect ratio" when an img is drawn in a box whose width-to-height ratio differs from the image file, so it looks stretched. Fix it by letting one dimension follow the other with height: auto, or keep the fixed box and add object-fit: cover so the image is cropped, not distorted.
<!--/QA-->

Lighthouse prints **Displays images with incorrect aspect ratio** when an `<img>` is drawn in a box whose shape does not match the shape of the image file, so the picture looks stretched or squashed. A square 800 x 800 product photo shown at 300 x 200 is the typical case. In our study of 269 Shopify storefronts, 52 of them (19.3%) failed this audit. It is a pass or fail check in the Best Practices category with a weight of 1. This page covers what Lighthouse compares, the CSS that causes the distortion, and the fix for each cause.

## TL;DR

- **What:** A list of images whose displayed width-to-height ratio differs from the ratio of the file itself.
- **Why it matters:** The image is visibly distorted. Faces, products and logos look wrong, and the page looks broken.
- **Fix:** Let one dimension follow the other (`height: auto`), or keep the fixed box and add `object-fit: cover` so the image is cropped instead of stretched.

## What does "Displays images with incorrect aspect ratio" mean?

Every image file has a natural size, for example 1200 x 800 pixels, and so a natural aspect ratio, here 1.50. The page then displays it at some size in CSS pixels. If the displayed ratio is different, the browser has stretched the image in one direction to fill the box.

Lighthouse lists each such image with two columns:

| Column | Example | Meaning |
|---|---|---|
| Aspect Ratio (Displayed) | `300 x 200 (1.50)` | The size of the box on the page and its ratio |
| Aspect Ratio (Actual) | `800 x 800 (1.00)` | The natural size of the file and its ratio |

Per the audit source, a difference of less than 2 pixels in the displayed size is ignored, so sub-pixel rounding does not fail it. One listed image fails the audit.

## Which images does Lighthouse check?

Only images that the browser is actually stretching. The audit skips:

- **Images with `object-fit` set to anything but the default.** With `cover`, `contain`, `scale-down` or `none`, the browser crops or letterboxes and does not distort. This is why `object-fit` is the usual fix.
- **CSS background images.** Lighthouse cannot tell a deliberate sprite or repeated pattern from a mistake.
- **SVG images.** They have no fixed natural size.
- **Very small images**, 5 pixels or less on a side, such as tracking pixels and spacers.
- **Images that are not displayed**, with a rendered width or height of zero.

So the list is short and specific: real `<img>` elements, with the default `object-fit: fill`, drawn in a box of the wrong shape.

## Why are my images displayed with the wrong aspect ratio?

1. **CSS sets both width and height.** A thumbnail grid or avatar rule such as `img { width: 300px; height: 200px; }` forces every image into one shape, whatever was uploaded.
2. **`height: 100%` or a fixed height with a fluid width.** The width follows the column and the height follows something else, so the ratio changes at every screen size.
3. **Flexbox stretching.** An `<img>` that is a direct child of a flex row gets the default `align-items: stretch` and grows to the height of the tallest sibling while its width stays put.
4. **Wrong `width` and `height` attributes.** Someone fixed [unsized images](/audits/unsized-images) by typing numbers that do not match the file, or the image was replaced and the old numbers stayed, and CSS without `height: auto` honors both.
5. **`srcset` candidates with different shapes.** A wide crop for desktop and a tall crop for mobile in one `srcset`, displayed in a box sized for only one of them.
6. **A CMS or app that outputs fixed dimensions.** Sliders, review widgets and logo strips often hard-code a box.

## How do I fix "Displays images with incorrect aspect ratio"?

### 1. Let the height follow the width

For images that should show whole, remove the fixed height:

```css
img {
  max-width: 100%;
  height: auto;
}
```

Keep the `width` and `height` attributes in the HTML, set to the real pixel size of the file. With `height: auto` the browser uses them only as a ratio, which reserves the right space and prevents layout shift.

### 2. Keep the box and crop with `object-fit`

For grids, cards and avatars where every image has to fill the same shape:

```css
.card img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}
```

`object-fit: cover` fills the box and crops the overflow. `object-fit: contain` shows the whole image with empty space around it, which suits logos. Use `object-position` to choose which part survives the crop.

### 3. Stop flexbox from stretching the image

```css
.row { display: flex; align-items: flex-start; }
/* or, on the image only */
.row > img { align-self: flex-start; }
```

Wrapping the image in a `<div>` and making the wrapper the flex item also works.

### 4. Correct the width and height attributes

Read the natural size in DevTools: hover the `<img>` in the Elements panel and the tooltip shows the rendered size and the intrinsic size. Set the attributes to the intrinsic numbers. If the image was replaced, update them.

### 5. Use `<picture>` for different crops

When mobile and desktop need different shapes, that is art direction, and `srcset` alone cannot describe it. Give each crop its own `<source>` with its own `width` and `height`:

```html
<picture>
  <source media="(max-width: 600px)" srcset="hero-tall.jpg" width="600" height="800">
  <img src="hero-wide.jpg" width="1600" height="900" alt="...">
</picture>
```

### 6. Crop the file itself

If a slot is always 3:2, serve a 3:2 file. The browser then has nothing to stretch or crop, and you ship fewer bytes than with a larger image cropped in CSS.

## How do I fix it in WordPress, Shopify, or Next.js?

- **WordPress:** register a hard-cropped size, `add_image_size( 'card', 600, 400, true );`, use it in the template, and regenerate thumbnails for old uploads. For a theme that forces a height in CSS, add `object-fit: cover` to that rule under Appearance, Customize, Additional CSS. Check sliders and logo carousels first; they are the usual source.
- **Shopify:** request the shape you need from the CDN, `{{ image | image_url: width: 600, height: 400, crop: 'center' }}`, and let `image_tag` write the `width` and `height` attributes instead of typing them. Where merchants upload mixed shapes into one grid, add `object-fit: cover` and an `aspect-ratio` to the card image.
- **Next.js:** with `next/image`, the `width` and `height` props must match the file's ratio. For a fixed slot, use the `fill` prop inside a positioned parent that has an `aspect-ratio`, and set `style={{ objectFit: 'cover' }}`.

## How do I verify the fix?

1. Re-run Lighthouse. "Displays images with incorrect aspect ratio" should move to the passed audits.
2. Resize the window from phone width to desktop width and watch the images that were listed. A ratio that is right at one width can be wrong at another.
3. In DevTools, hover a fixed image in the Elements panel and compare the rendered size with the intrinsic size. The two ratios should match, or `object-fit` should be set.
4. Run Lighthouse in both mobile and desktop modes. The mobile run only sees the mobile layout.

## What mistakes should I avoid?

- **Deleting the `width` and `height` attributes.** That fixes the distortion and brings back layout shift and the unsized-images audit. Correct them, and add `height: auto`.
- **Using `object-fit: cover` without checking the crop.** Heads and product edges get cut off. Set `object-position`, or use `contain` for logos and packshots.
- **Fixing one breakpoint.** Test every layout the image appears in.
- **Hiding the problem behind a background image.** Moving the picture to CSS `background-image` passes the audit because Lighthouse skips backgrounds, and it costs you the `alt` text, lazy loading and `srcset`.
- **Treating it as a score problem.** The audit weighs little in Best Practices. Fix it because visitors see stretched pictures.

## Related audits

- [Image elements do not have explicit width and height](/audits/unsized-images): the attributes that reserve space, which must match the file's ratio
- [Cumulative Layout Shift](/audits/cumulative-layout-shift): what wrong or missing image dimensions cost
- [Image elements do not have alt attributes](/audits/image-alt): the other check on every `<img>`
- [Serve images in next-gen formats](/audits/modern-image-formats): smaller files once the shape is right

---

Audit your URL at https://lighthouse-md.com.
