Skip to content
Learn Measure Blog Case studies About
On this page
  • How the Lighthouse image aspect ratio audit fails
  • Ensure images display with the correct aspect ratio
    • Use an image CDN
    • Check the CSS that affects the image's aspect ratio
    • Check the image's width and height attributes in the HTML
  • Resources

Displays images with incorrect aspect ratio

May 2, 2019 — Updated Apr 29, 2020
Available in: Español, 한국어, Português, 中文, English
Appears in: Best Practices audits
On this page
  • How the Lighthouse image aspect ratio audit fails
  • Ensure images display with the correct aspect ratio
    • Use an image CDN
    • Check the CSS that affects the image's aspect ratio
    • Check the image's width and height attributes in the HTML
  • Resources

If a rendered image has an aspect ratio that's significantly different from the aspect ratio in its source file (the natural aspect ratio), the rendered image may look distorted, possibly creating an unpleasant user experience.

How the Lighthouse image aspect ratio audit fails #

Lighthouse flags any image with a rendered dimension more than a few pixels different from the expected dimension when rendered at its natural ratio:

Lighthouse audit shows images displayed with incorrect aspect ratio

There are two common causes for an incorrect image aspect ratio:

  • An image is set to explicit width and height values that differ from the source image's dimensions.
  • An image is set to a width and height as a percentage of a variably-sized container.
Each Best Practices audit is weighted equally in the Lighthouse Best Practices Score. Learn more in The Best Practices score.

Ensure images display with the correct aspect ratio #

Use an image CDN #

An image CDN can make it easier to automate the process of creating different sized versions of your images. Check out Use image CDNs to optimize images for an overview and How to install the Thumbor image CDN for a hands-on codelab.

Check the CSS that affects the image's aspect ratio #

If you're having trouble finding the CSS that's causing the incorrect aspect ratio, Chrome DevTools can show you the CSS declarations that affect a given image. See Google's View only the CSS that's actually applied to an element page for more information.

Check the image's width and height attributes in the HTML #

When possible, it's good practice to specify each image's width and height attributes in your HTML so that the browser can allocate space for the image. This approach helps to ensure that content below the image doesn't shift once the image is loaded.

However, specifying image dimensions in HTML can be difficult if you're working with responsive images because there's no way to know the width and height until you know the viewport dimensions. Consider using the CSS Aspect Ratio library or aspect ratio boxes to help preserve aspect ratios for responsive images.

Finally, check out the Serve images with correct dimensions post to learn how to serve images that are the right size for each user's device.

Resources #

  • Source code for Displays images with incorrect aspect ratio audit
  • CSS Aspect Ratio
  • Aspect Ratio Boxes
  • Serve images with correct dimensions
Last updated: Apr 29, 2020 — Improve article
Return to all articles
Share
subscribe

Contribute

  • File a bug
  • View source

Related content

  • developer.chrome.com
  • Chrome updates
  • Web Fundamentals
  • Case studies
  • Podcasts
  • Shows

Connect

  • Twitter
  • YouTube
  • Google Developers
  • Chrome
  • Firebase
  • Google Cloud Platform
  • All products
  • Terms & Privacy
  • Community Guidelines

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies.