🧩 The Image That Was Lazy Forever
Native lazy loading decides whether to fetch an image based on its position relative to the viewport, which works well for images further down a normally visible page – but an image placed inside a tab panel, an accordion section, or any other container hidden with a display-none style has no meaningful viewport position at all while it stays hidden, and the browser can simply never decide the image is close enough to load. The moment the user actually clicks the tab and the container becomes visible, the image’s layout position is recalculated, but by then the lazy-loading decision has already been made and missed, leaving a blank space where the image should be until the user scrolls in a way that happens to retrigger the check.
🔎 The Problem
<div class="tab-panel" id="specs" style="display: none;">
<!-- Hidden by display:none until the user clicks the "Specs" tab -->
<img src="diagram.png" loading="lazy" alt="Product diagram">
</div>
<script>
tabButton.addEventListener('click', () => {
specsPanel.style.display = 'block';
// The image's loading="lazy" decision was already evaluated
// while display:none meant it had no real position on the
// page at all - some browsers simply never revisit that
// decision once the element becomes visible later, leaving
// the image unloaded even though it is now clearly on screen.
});
</script>
✅ Fix: Don’t Ask Lazy Loading to Judge an Element With No Position
- Switch the image’s loading attribute from lazy to eager for any image inside a tab, accordion, or other initially hidden container, since the performance benefit of lazy loading assumes a real scroll position to measure against in the first place.
- Trigger the browser to re-evaluate the image, such as by briefly toggling the src attribute or forcing a reflow, at the exact moment the containing tab or panel becomes visible, if keeping lazy loading on that image is still worth the extra handling.
- Use a visibility-based loading approach built specifically for this case – loading the image the moment its container’s hidden state changes – rather than relying on the browser’s own viewport-distance heuristic to somehow account for content it currently cannot see at all.
⚠️ Why This Is Easy to Miss
- Lazy loading behaves exactly as expected for every image lower down a normal, fully visible page, so there is nothing to suggest it needs different treatment for an image that starts out hidden in a tab rather than merely off-screen below the fold.
- The blank space where the image should be often gets attributed to a slow network or a broken image path, since nothing in the browser’s behavior visibly announces that a loading decision was made and simply never revisited once the tab opened.
Lazy loading decides based on where an element is on the page – an element with display:none isn’t anywhere on the page yet, and that decision never gets a second chance.




