CLS Image Layout Shift: Why It Happens and How to Fix It

PublishedToolPlaceholder Image Generator

Contents
  1. Why the screen shifts after images load
  2. How to prevent the shift: try it yourself
  3. Common sticking points
  4. The bottom line
  5. Frequently asked questions

You've probably seen it: an image loads late, and the content below it suddenly jumps down the page. This has a name — CLS (Cumulative Layout Shift) — and a clear cause. The browser doesn't know the image's size until the file downloads.

Summary ① If an image has no width or height set, the browser only learns its real size after the download finishes — and the layout shifts at that moment (CLS). ② If you declare the size up front with the HTML width and height attributes or CSS aspect-ratio, the browser reserves the space before the image loads. ③ If the final image isn't ready yet, you can drop in a placeholder image with the same pixel dimensions to check for and prevent the shift.

Why the screen shifts after images load

When the browser draws a page, it calculates the space each element takes from top to bottom. If an <img> tag has no size information, the browser reserves almost zero space for it and only learns the actual pixel width and height once the image file has fully downloaded.

At that moment, the browser recalculates the layout to make room for the image. Any text or buttons below it get pushed down by that amount — and CLS, one of the Core Web Vitals Google introduced, is the metric that measures how big those shifts are.

This is worse on slow connections, like mobile. A paragraph you're reading jumps and you end up tapping the wrong button — a common experience on pages with high CLS.

How to prevent the shift: try it yourself

The most reliable fix is to put the real size on the image tag in advance. Set the pixel width and height, like width="1200" height="630", and the browser reserves space at that ratio before it even downloads the file. CSS's aspect-ratio property does the same job.

The problem is when the final image isn't ready yet. During design mockups or development, you need something to hold the spot instead of the real photo — and if the size doesn't match, the layout shifts all over again the moment you swap in the real image.

In that case, create a temporary image with the exact same pixel width and height as the final image and put it in place first. You can do this in an image editor by creating a new canvas at the size you want, filling it with a background color, and saving it.

Check it with our tool. Instead of opening an image editor and creating a canvas every time, just enter the width and height and download an image at exactly that size.

Placeholder Image Generator

Free · no signup · runs in your browser only (nothing is sent to a server)

The size values and label shown on screen are pixels drawn into the image itself, so if you put this file in place, the width and height of that spot stay exactly right until you swap in the real image.

Common sticking points

SituationWhat actually happens
No width or height on <img> at allThe browser draws without knowing the size, and the layout shifts when the image finishes loading
Placeholder size differs from the final imageThe layout shifts again by that difference when you swap in the real image
width and height set, but not matching the real ratioThe image can look stretched or squished
Using only CSS aspect-ratio and skipping width and heightModern browsers reserve the space, but if you need to support older ones, add the attributes too

The bottom line

The CLS jump after images load comes from one simple fact: the browser doesn't know the image size in advance. Set the pixel width and height on the <img> tag, or specify CSS aspect-ratio, and most cases are solved.

During development or design, when the final image doesn't exist yet, putting a placeholder image of the same size in its place is enough to keep working without any layout shift.

Placeholder Image Generator

Free · no signup · runs in your browser only (nothing is sent to a server)

Frequently asked questions

What happens if I set width and height but the real image has a different ratio?

The browser reserves space based on the width and height you set, but if the original image has a different ratio, CSS can make it look stretched or squished. Space reservation is separate from that — set the size to match the final image's ratio, and the layout won't shift and the image won't distort.

If I use CSS aspect-ratio, can I skip the width and height attributes?

In modern browsers, aspect-ratio alone reserves the space before the image loads. But some older browsers don't support the property, so if you need broad compatibility, it's safer to include the width and height attributes as well.

Do the size and label text stay on the downloaded file?

Yes. The text you see on screen is drawn onto the canvas and saved as-is into the PNG, JPG, or WebP file, so it's baked into the image when you open the download. Before using it in production, replace it with the real image that doesn't have that text.

How do I check how much the screen is shifting?

Enter your page URL in the Lighthouse panel of Chrome DevTools or in Google PageSpeed Insights, and it reports the CLS score along with which elements caused the shifts. Compare the score before and after you set image sizes, and you'll see the effect right away.

This article was adapted from our Korean original. Read the Korean original

Related articles

  1. QR code grid pattern: why it looks that way and why it scansQR codes look like random black-and-white grids for a reason. See what finder patterns do and how error correction keeps a code scannable when covered or colored.
  2. QR Error Correction Levels L, M, Q, H: What Each One MeansL, M, Q, and H recover about 7%, 15%, 25%, and 30% of a QR code. See why higher levels add cells and how a damaged code still reads.
  3. Random Number Picker Algorithm: Math.random vs CSPRNGHow Math.random, CSPRNG, and Fisher-Yates shuffling affect draw fairness, plus how to pick winners without bias.
  4. 301 vs 302 Redirects: Why a 301 Is Hard to Undo301 is permanent, 302 is temporary. How search engines and browsers treat each, why a wrong 301 is hard to undo, and how to check with curl.
  5. Resume photo URL not showing: how to check a direct image linkPasted a photo URL into Resume Builder but it won't show in the preview or PDF? Learn why page links fail and how to find the direct image link.
  6. robots.txt Disallow vs noindex: Why Blocked Pages Still ShowDisallow only blocks crawling, not indexing. So blocked URLs can still show up in search results without a snippet. Here's how noindex differs.

Related tools