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.
<img src="...">- Viewport height
- --
- Media before / after
- --
- Target movement
- --
width="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
- Optimize Cumulative Layout Shift - images without dimensions - Google web.dev, checked 2026-08-06
- HTML Standard - presentational hints for width and height - WHATWG, checked 2026-08-04
- Layout Instability API - Web Platform Incubator Community Group, checked 2026-08-04
Formal evidence
Browser and viewport matrix
Cells show failing / fixed target movement in CSS pixels.
| Browser | 320 | 375 | 768 | 1024 | 1440 |
|---|---|---|---|---|---|
| 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-320149pxchromium-fixed-movement-3200pxchromium-horizontal-reflow-3200px / 0pxchromium-layout-instability-api-3200.07806582641601562 / 0chromium-failing-movement-375179pxchromium-fixed-movement-3750pxchromium-horizontal-reflow-3750px / 0pxchromium-layout-instability-api-3750.07714520254629628 / 0firefox-failing-movement-320149pxfirefox-fixed-movement-3200pxfirefox-horizontal-reflow-3200px / 0pxfirefox-failing-movement-375179pxfirefox-fixed-movement-3750pxfirefox-horizontal-reflow-3750px / 0pxwebkit-failing-movement-320149pxwebkit-fixed-movement-3200pxwebkit-horizontal-reflow-3200px / 0pxwebkit-failing-movement-375179pxwebkit-fixed-movement-3750pxwebkit-horizontal-reflow-3750px / 0px
Run 2026-08-04T11-36-57-234Z. chromium 149.0.7827.201, firefox 153.0, webkit 26.5. Open raw manifest