ampproject / ampproject/amphtml
amp-img won't render when nested in a hidden element
- Dominant language
- JavaScript
- Stars
- 14.9k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
If you have a bug for AMP please fill in the following template. Delete everything except the headers (including this text).
## What's the issue?
amp-img won't render
## How do we reproduce the issue?
Try the following example on the playground https://playground.amp.dev/amp/
```
My AMP Page
body {
-webkit-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
-moz-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
-ms-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
animation: -amp-start 8s steps(1, end) 0s 1 normal both
}
@-webkit-keyframes -amp-start {
from {
visibility: hidden
}
to {
visibility: visible
}
}
@-moz-keyframes -amp-start {
from {
visibility: hidden
}
to {
visibility: visible
}
}
@-ms-keyframes -amp-start {
from {
visibility: hidden
}
to {
visibility: visible
}
}
@-o-keyframes -amp-start {
from {
visibility: hidden
}
to {
visibility: visible
}
}
@keyframes -amp-start {
from {
visibility: hidden
}
to {
visibility: visible
}
}
body {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none
}
.hidden {
display: none
}
#myinput:checked + .hidden {
display: block
}
MyInput
test
```
Please provide a public URL and ideally a reduced test case (e.g. on jsbin.com) that exhibits only your issue and nothing else. Provide step-by-step instructions for reproducing the issue:
1. Here we have a deeply nested amp-img in an initially hidden div.
2. When clicking on the checkbox the div will become visible, but the amp-img won't load or it will load randomly.

## What browsers are affected?
I've tried on firefox / chrome and get consistent behaviour in the playground
## Which AMP version is affected?
Powered by AMP ⚡ HTML – Version 2104170104001
Contributor guide
Research direction
Reproduce the nested amp-img case in the AMP Playground using the provided HTML and checkbox steps, then trace the amp-img behavior when its parent changes from display:none to visible. Done means the image renders consistently after the hidden container is revealed in Firefox and Chrome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100