All cases
RL-012 / Layout ShiftEvidence verified

Prevent Image Layout Shifts With Width and Height

A project-owned image receives its source after initial layout; without dimensions the following content moves when the image becomes available, while width and height reserve its aspect ratio in advance.

Experiment mode

Fixture viewport

Failing<img src="...">
Viewport height
--
Media before / after
--
Target movement
--
Fixedwidth="640" height="360"
Viewport height
--
Media before / after
--
Target movement
--

Three-browser evidence verified. Live values come from your current browser. The formal matrix records the controlled browser runs and fixture revision used for the published conclusion.

Observed failure

The article is laid out before the image has a height

The failing image begins with a zero-height box because it has no source or dimension attributes. Assigning the source reveals a 16:9 asset and pushes the following content down after initial layout.

Minimal code diff

Expose the image ratio in the initial markup

Keep responsive `width: 100%; height: auto`, and add accurate `width` and `height` attributes so the browser can derive and reserve the aspect ratio before the resource loads.

Before

<img src="layout-check.png" alt="...">

After

<img
  src="layout-check.png"
  width="640" height="360"
  alt="...">

Root cause

Responsive CSS controls the final rendered size, but it cannot reserve a missing intrinsic ratio before the resource is known. Without width and height attributes or another explicit ratio, the image begins at zero height and later expands, moving content that has already been laid out.

Accurate dimension attributes provide a ratio before the image source finishes loading. width: 100% and height: auto can still make the rendered image responsive; the attributes do not require a fixed 640-pixel display width.

Measurement support

Every browser run records the image height before and after source assignment plus the following content’s vertical movement. Chromium additionally records layout-shift performance entries that do not follow recent input. Firefox and WebKit results do not claim Layout Instability API support when that entry type is unavailable.

When this fix is not enough

The attributes must match the selected asset’s ratio. Art-directed <picture> sources with different crops may need source-specific dimensions. Lazy-loaded media, ads, embeds, fonts, and dynamically inserted notices can create separate shifts that require their own reserved space and measurement.

Regression condition

At 320 and 375 CSS pixels, the failing image must grow from zero height and move the following content by a positive number of pixels. The fixed image must reserve the same height before loading and leave the following content in place. Chromium must also report positive non-input layout shift for failing and zero for fixed.

Primary references

Sources checked for this case

  1. Optimize Cumulative Layout Shift - images without dimensions - Google web.dev, checked 2026-08-06
  2. HTML Standard - presentational hints for width and height - WHATWG, checked 2026-08-04
  3. Layout Instability API - Web Platform Incubator Community Group, checked 2026-08-04

Formal evidence

Browser and viewport matrix

Three-browser run

Cells show failing / fixed target movement in CSS pixels.

Browser32037576810241440
Chromium+149 / +0+179 / +0+401 / +0+545 / +0+779 / +0
Firefox+149 / +0+179 / +0+401 / +0+545 / +0+779 / +0
WebKit+149 / +0+179 / +0+401 / +0+545 / +0+779 / +0
20/20 recorded assertions passed
  • chromium-failing-movement-320149px
  • chromium-fixed-movement-3200px
  • chromium-horizontal-reflow-3200px / 0px
  • chromium-layout-instability-api-3200.07806582641601562 / 0
  • chromium-failing-movement-375179px
  • chromium-fixed-movement-3750px
  • chromium-horizontal-reflow-3750px / 0px
  • chromium-layout-instability-api-3750.07714520254629628 / 0
  • firefox-failing-movement-320149px
  • firefox-fixed-movement-3200px
  • firefox-horizontal-reflow-3200px / 0px
  • firefox-failing-movement-375179px
  • firefox-fixed-movement-3750px
  • firefox-horizontal-reflow-3750px / 0px
  • webkit-failing-movement-320149px
  • webkit-fixed-movement-3200px
  • webkit-horizontal-reflow-3200px / 0px
  • webkit-failing-movement-375179px
  • webkit-fixed-movement-3750px
  • webkit-horizontal-reflow-3750px / 0px