Small SEO Tools

How to Reserve Space Before an Image Loads

Text can move down a page when an image arrives because the browser did not have the right space ready for it. Give the image’s proportions to the page before the file finishes loading, then check the following content during a fresh load.

This walkthrough uses the Image Resizer to read a file’s dimensions. The repair is in the page markup and CSS; the example keeps the same image file throughout.

Confirm the dimensions of the image actually used

Keep a local copy of the file delivered by your page. Open it in the resizer using Choose an image to resize. The current displayed input limit is 20 MB. After it loads, read Original size and the populated Width and Height fields.

Our synthetic decorative PNG loads as 640 by 360. Those numbers describe a 16:9 image. This dimension check uses the loaded original; it does not require a resize or export.

Check the file the page serves rather than assuming an earlier master has the same shape. A publishing system may have selected a cropped copy. If the page offers several image resources, inspect the selected resource too; the guide to image resources and displayed size covers that separate choice.

Reserve the ratio and keep the display responsive

For this 640 by 360 decorative example, start with matching attributes:

<img class="story-image"
     src="/images/decorative-banner.png"
     width="640" height="360"
     alt="">

Add the example’s responsive display rule:

.story-image {
  display: block;
  width: 100%;
  height: auto;
}

The attributes use integer numbers without px. MDN’s image element reference explains how width and height let the browser calculate an aspect ratio before loading. CSS still determines the displayed size. Here, a 320-pixel-wide container needs 180 pixels of image height; a 240-pixel container needs 135.

The empty alternative belongs to this decorative sample. Use alternative text appropriate to your real image’s role. Also inspect existing styles: a fixed height or another rule can change how the image fits, so adding attributes alone is not a complete layout review.

Compare the space before and after loading

We ran the current resizer code locally in Chrome and independently decoded the source PNG to confirm 640 by 360 pixels. Six local HTTP pages then used exactly the same file bytes. We held each image response until its pending layout was measured, released it and measured again after decoding.

Container and attributes Image height before to after Following paragraph movement
320 wide, dimensions missing 0 to 180 180 down
320 wide, 640 by 360 180 to 180 0
320 wide, incorrect 640 by 640 320 to 180 140 up
240 wide, dimensions missing 0 to 135 135 down
240 wide, 640 by 360 135 to 135 0
240 wide, incorrect 640 by 640 240 to 135 105 up

All measurements are CSS pixels. The correct ratio kept the paragraph in place in both containers. Guessing square attributes reserved too much height, so the paragraph moved upward when the actual image proportions became available.

The native browser also recorded layout-shift entries in the missing and incorrect cases, and none in the matching cases. These are observations from one controlled decorative-image fixture with the CSS above, not a prediction of a website’s overall CLS score.

Check the saved page during a fresh load

  1. Inspect the actual image element and confirm that both dimension attributes survived saving.
  2. Reload with browser caching disabled or a suitable network delay so you can observe the period before the image arrives.
  3. Watch the image area and the text immediately after it. Check the computed image width and height in the pending and loaded states.
  4. Repeat at the narrower layouts your page supports, especially if its template changes styles at a breakpoint.

Google’s layout-shift guidance describes reserving image space and using browser performance tools to locate movement. The visibly shifted paragraph may be the element affected by an image above it. Trace the cause before changing the paragraph’s margins.

If the content still moves, check whether the delivered image has a different ratio or whether another component changes size. Images are one possible cause; fonts, embeds and inserted content also deserve investigation. Keep the fix tied to the movement you observed in the final page.