Fix guides · Performance

How to fix “Image elements do not have explicit width and height”

Images without a width and height make your page jump as they load, which annoys visitors and hurts your Core Web Vitals. How to fix it on Shopify, WordPress, Webflow, Wix, Squarespace and Next.js.

Time to fix
15–45 minutes
Skill needed
Copy and paste
Who notices
Every visitor: text and buttons jump while the page loads

Why it matters

Until an image downloads, the browser doesn't know how tall it will be. It lays out the page without it, then pushes everything down when the image arrives. Visitors lose their place, or tap the wrong button.

That movement is measured as Cumulative Layout Shift (CLS), one of Google's three Core Web Vitals.

“Always include width and height size attributes on your images and video elements.”

web.dev: Optimize Cumulative Layout Shift

Before you start

  • The width and height attributes don't fix an image's displayed size. They tell the browser its shape, so it can reserve the right space. CSS still makes it responsive.
  • Use the image file's real pixel dimensions (or the same proportions), or the image will look stretched.

Fix it on your platform

Shopify

  1. Images output with Shopify's image_tag filter get width and height automatically, so most images in current themes are fine.
  2. Flagged images usually come from an app or from older theme code that writes <img> tags by hand. Check which image your report lists.
  3. In the theme code (Online Store → Themes → ⋯ → Edit code), replace a hand-written <img> with image_url and image_tag. If it comes from an app, ask the app's developer.
Liquid
{{ section.settings.image | image_url: width: 1200 | image_tag }}

WordPress

  1. WordPress adds width and height to images in your post and page content automatically (since version 5.5).
  2. Flagged images usually come from your theme's templates, a slider or page builder plugin, or a Custom HTML block. Check which image your report lists.
  3. For a plugin or page builder, check its image settings or update it. For a Custom HTML block, add the attributes yourself. Theme developers can output images with wp_get_attachment_image(), which includes them.

Webflow

  1. Select the image, open Image settings and set Width and Height in pixels, using the image's real proportions.
  2. Images inside rich text may be output without dimensions. As a fallback, give the image (or its wrapper) a fixed aspect ratio with CSS, so the space is reserved before it loads.
CSS fallback
.blog-body img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
}

Wix Managed by the platform

  1. Wix writes the image code for elements you add in the editor, so you can't add these attributes yourself.
  2. If we flagged an image, check whether it comes from custom code (an Embed HTML element). There, you can add width and height to the <img> tag directly.

Squarespace Managed by the platform

  1. Squarespace writes the image code for its blocks and sections, so you can't add these attributes yourself.
  2. If we flagged an image, check whether it comes from a Code block or code injection. There, you can add width and height to the <img> tag directly.

Next.js

  1. next/image always sets dimensions: statically imported images get them automatically, and remote images need width and height props (or fill inside a sized container).
  2. Flagged images are usually plain <img> tags. Switch them to next/image, or add width and height.
next/image
import hero from "./hero.jpg";

<Image src={hero} alt="…" /> {/* size read from the file */}
<Image src="https://cdn.example.com/a.jpg" width={1200} height={800} alt="…" />

Any other site

  1. Add width and height to each <img> tag, and keep it responsive with CSS.
HTML
<img src="team.jpg" width="1200" height="800" alt="Our team at the studio">
CSS
img {
  max-width: 100%;
  height: auto;
}

“To provide a good user experience, sites should strive to have a CLS score of 0.1 or less.”

web.dev: Cumulative Layout Shift

Check that it's fixed

  • Re-run your StudioLNC audit: the issue should be gone, or list fewer images.
  • Real-visitor CLS (in your site's Core Web Vitals charts) is averaged over 28 days, so it improves gradually over the following weeks.

Find every issue like this on your site

Free audit of performance, accessibility, SEO and security, with fixes for your platform.