TechBuzzPro

Why AMP Images Disappear When Dimensions Are Missing

· 6 min read · Apps & Browsers

In this article
  1. Why AMP requires image dimensions
  2. How AMP image sizing works
  3. Choosing the right layout and dimensions
  4. Diagnosing an image that does not appear
  5. Common mistakes and misconceptions
  6. Frequently Asked Questions

AMP images can disappear or fail to render when their required dimensions are missing because AMP needs to reserve a predictable area for each image before the file loads. Add valid width and height values—or use a supported responsive layout with the required sizing information—and check that the image source can load.

Why AMP requires image dimensions

AMP pages are built to keep layout changes controlled as content loads. A browser ordinarily discovers an image’s natural size after it fetches the file; until then, it may not know how much space to leave. If the image later expands the page, text and other elements move. This movement is called layout shift.

AMP addresses this by requiring dimensions or equivalent layout information on elements such as <amp-img>. The browser can use the supplied aspect ratio to allocate space in advance, even before it has downloaded the image. That makes the page’s initial layout more predictable and prevents an image from unexpectedly pushing content down.

So “disappear” can describe more than one behavior. An AMP validator may reject the markup, a development environment may report an error, or the element may end up with no usable display area. The missing dimensions are a markup or layout problem; they do not necessarily mean the image file itself has been deleted or is unavailable.

How AMP image sizing works

AMP uses the dimensions and layout attributes to determine the box that an image should occupy. For example, an image that is 1200 pixels wide and 800 pixels high has a 3:2 aspect ratio. If it is displayed at 600 pixels wide while preserving that ratio, its displayed height is 400 pixels.

A basic AMP image might look like this:

<amp-img src="/images/field.jpg"
  width="1200" height="800"
  layout="responsive"
  alt="A field beneath a cloudy sky">
</amp-img>

Here, width and height describe the image’s intrinsic proportions, while layout="responsive" tells AMP to scale it to fit its container and preserve those proportions. The numbers do not mean that the image must always appear at exactly 1200 by 800 CSS pixels. They provide sizing information from which the responsive display can be calculated.

AMP’s image component is not the same as a plain HTML <img>. AMP markup has component-specific validation and layout requirements. A page can therefore look plausible in an ordinary browser while still containing invalid AMP markup.

Choosing the right layout and dimensions

Use the layout that matches the way the image should behave. The right choice depends on whether the image should scale, keep a fixed size, or fill a defined area.

  • Responsive: Supply the image’s proportional width and height and let it scale with its container. This is a common choice for article images that should fit different screen widths.
  • Fixed: Use dimensions for a fixed rendered size when the image should not expand to fill available space. Make sure the chosen size fits the page design.
  • Fill: Use a parent with a defined size when the image should occupy that area. Check the AMP layout requirements for the component and container; simply omitting dimensions is not a substitute for defining the space.
  • Intrinsic: Where supported and appropriate, this layout can use the image’s natural dimensions while still providing AMP with the sizing information it requires.

For responsive images, enter the source image’s actual aspect ratio rather than the dimensions at which you hope it will appear. If an image is cropped to a different ratio in the page, use dimensions that represent the rendered asset or intended box and check the result across viewport widths.

Diagnosing an image that does not appear

Missing dimensions are a common cause, but they are not the only one. After adding valid sizing information, inspect the markup and the image request rather than assuming that every blank area has the same cause.

  1. Validate the AMP document. Look for errors identifying a missing attribute, invalid value, or unsupported element. Correct the reported issue and validate again; one error can sometimes obscure later problems.
  2. Check both dimensions. Confirm that the required width and height are present, numeric, greater than zero, and consistent with the intended aspect ratio. A value of zero or a typo does not create a useful display box.
  3. Check the layout attribute. Make sure the selected layout is supported for the element and matches the structure around it. Responsive layouts need room in their parent container.
  4. Inspect the source URL. Verify that the URL is correct and that the file is reachable. A 404 response, blocked request, or incorrect path can prevent an otherwise valid AMP image from loading.
  5. Check browser developer tools. The console can reveal markup or runtime errors, while the network panel can show whether the image request succeeded. Distinguish a missing file from an element that has no visible space.
  6. Recheck after publishing. If the source is generated by a template or content system, make sure that system outputs dimensions consistently, including for newly added images.

Common mistakes and misconceptions

“The dimensions must match the screen.” Not for a responsive image. The supplied values establish proportions; the displayed width can change with the available space.

“Any numbers will make it work.” Incorrect dimensions may distort the layout’s reserved space or produce an unwanted crop. Use values that reflect the asset’s real ratio or the intended display box.

“Dimensions fix every blank image.” They fix a sizing requirement, not a broken URL, inaccessible file, unsupported markup, or other loading error. Validate the document and check the request separately.

“CSS width and height always replace AMP attributes.” Styling controls appearance, but it does not necessarily satisfy AMP’s markup and layout requirements. Follow the requirements for the AMP element itself.

Also avoid confusing the HTML attributes with CSS units. AMP dimension attributes are numeric values; do not write values such as width="100%" where a numeric dimension is expected. Use the appropriate layout behavior for fluid sizing.

Frequently Asked Questions

Do AMP images need both width and height?
AMP image markup generally needs width and height, or a valid sizing arrangement specified by its supported layout. Consult the component’s validation requirements for the exact markup being used.

Will adding dimensions make a missing image file appear?
No. Dimensions tell the page how to size the image area. The source URL must still point to a reachable image file.

What dimensions should I use for a responsive AMP image?
Use values that represent the source image’s aspect ratio, such as 1200 by 800 for a 3:2 image. The responsive layout can then scale it to fit the available width.

Can I use CSS instead of width and height attributes?
CSS can style an image, but it may not satisfy AMP’s required markup or provide the early layout information AMP needs. Use the sizing attributes and layout supported by the AMP component.

Why is the image still blank after I add dimensions?
Check the image URL, network response, AMP validation output, container size, and browser console. A valid size does not resolve loading failures or unrelated markup errors.

Do missing dimensions affect SEO?
They can cause AMP validation or layout problems, but dimensions alone do not determine search visibility. Ensure the page and image are valid, accessible, and presented with appropriate alternative text.