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.”
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
- Images output with Shopify's image_tag filter get width and height automatically, so most images in current themes are fine.
- Flagged images usually come from an app or from older theme code that writes <img> tags by hand. Check which image your report lists.
- 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.
{{ section.settings.image | image_url: width: 1200 | image_tag }}WordPress
- WordPress adds width and height to images in your post and page content automatically (since version 5.5).
- 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.
- 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
- Select the image, open Image settings and set Width and Height in pixels, using the image's real proportions.
- 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.
.blog-body img {
width: 100%;
aspect-ratio: 3 / 2;
object-fit: cover;
}Wix Managed by the platform
- Wix writes the image code for elements you add in the editor, so you can't add these attributes yourself.
- 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
- Squarespace writes the image code for its blocks and sections, so you can't add these attributes yourself.
- 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
- 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).
- Flagged images are usually plain <img> tags. Switch them to next/image, or add width and height.
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
- Add width and height to each <img> tag, and keep it responsive with CSS.
<img src="team.jpg" width="1200" height="800" alt="Our team at the studio">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.”
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.