Do not load IMG that remains invisible for the user.
Description
Do not load IMG that remains invisible for the user. This rule identifies images that are not visible within the user’s viewport and are still being loaded eagerly, consuming network bandwidth, memory, and CPU resources without providing any immediate value. When images sit outside the visible area, browsers must still download, decode, and render them, which directly degrades page load speed, increases data usage, and harms overall performance.
The rule applies specifically to <img> elements that are neither hidden, have zero/tiny dimensions, nor use loading="lazy". It skips base64-encoded images (which are already inline) and only flags images that fall outside the current viewport. Off-screen eager-loaded images compete with above-the-fold content for bandwidth, delaying Largest Contentful Paint and increasing Total Blocking Time.
Common impact areas
- End users: users on slow or metered connections experience significantly slower page loads and higher data consumption when off-screen images download eagerly. This is especially harmful on mobile devices with limited bandwidth.
- Search engines: page speed is a confirmed ranking signal. Lazy-loading only above-fold images while eagerly loading off-screen ones inflates page weight and slows crawling, negatively impacting SEO rankings and Core Web Vitals scores.
- Site owners: unnecessary image transfers increase server bandwidth costs and CDN egress charges. Poor Lighthouse and PageSpeed Insights scores can affect conversion rates and user retention.
- Developers: teams must audit image loading strategies across templates, components, and CMS outputs. Failing to detect invisible eagerly-loaded images leads to performance regressions that are difficult to trace back to specific deployments.
- Maintainers: ongoing monitoring is required because new content or layout changes can shift images out of the viewport without anyone updating their loading attributes, silently degrading performance over time.
Why it matters
Performance is a core pillar of user experience. Every byte transferred and every image decoded consumes resources that could be directed toward rendering the content users actually see. The median mobile webpage transfers over 2 MB of data, and images account for roughly half of that.
Off-screen eager-loaded images directly degrade Core Web Vitals metrics. They increase Largest Contentful Paint by competing for bandwidth, inflate Total Blocking Time as the browser decodes large images, and contribute to Cumulative Layout Shift when images finally render and push content around. Core Web Vitals scores are also a Google ranking signal, meaning invisible images loaded eagerly can hurt both user experience and search visibility.
By deferring off-screen images via loading="lazy" or JavaScript-based lazy loading, you free up bandwidth for critical above-the-fold resources. This reduces initial payload, speeds up Time to Interactive, and ensures browsers prioritize rendering what users see first.
Coding problems and solutions
Common coding problems
- No loading attribute on any images: all images download at page load regardless of their position, causing massive unnecessary network activity on long pages.
- Using loading=”lazy” on above-the-fold images: deferring images that the user sees immediately delays rendering and worsens Largest Contentful Paint.
- CSS-hidden images still downloading: images wrapped in containers with
display: noneorvisibility: hiddencan still trigger downloads if theimgelement itself lacks proper attributes. - Carousels and sliders with many eager images: a hero carousel with 5 slides each containing a full-resolution image loads all 5 at once, but only 1 is ever visible.
- Grid/gallery layouts loading all images eagerly: product grids or image galleries with dozens of items eagerly download every image, overwhelming the network on initial load.
- CMS or template defaults ignoring lazy loading: content authors add images through a CMS that outputs
<img>tags withoutloading="lazy"or any deferred loading strategy.
How to fix it
Add loading=”lazy” to off-screen images
The simplest fix is to add the native loading="lazy" attribute to images that are not immediately visible. Reserve eager loading for above-the-fold images.
<!-- Above the fold: eager (default) -->
<img src="hero.webp" alt="Hero banner" width="1200" height="600">
<!-- Below the fold: lazy -->
<img src="feature.webp" alt="Feature showcase" width="600" height="400" loading="lazy">
<!-- All images download eagerly, even those far below the fold -->
<img src="hero.webp" alt="Hero banner" width="1200" height="600">
<img src="feature1.webp" alt="Feature 1" width="600" height="400">
<img src="feature2.webp" alt="Feature 2" width="600" height="400">
<img src="feature3.webp" alt="Feature 3" width="600" height="400">
<img src="feature4.webp" alt="Feature 4" width="600" height="400">
Use JavaScript lazy loading for browsers without native support
For older browsers or complex loading strategies, use an Intersection Observer to load images only when they approach the viewport.
const lazyImages = document.querySelectorAll('img[data-src]');
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.removeAttribute('data-src');
observer.unobserve(img);
}
});
}, { rootMargin: '200px' });
lazyImages.forEach((img) => imageObserver.observe(img));
// Loads ALL images immediately on page load – defeats the purpose
document.querySelectorAll('img[data-src]').forEach((img) => {
img.src = img.dataset.src;
});
Avoid lazy-loading above-the-fold images
Never apply loading="lazy" to images that appear immediately in the viewport, as this delays rendering and worsens Largest Contentful Paint.
<!-- Hero image: visible immediately, must load eagerly -->
<img src="hero.webp" alt="Welcome banner" width="1200" height="600" fetchpriority="high">
<!-- Footer images: far below fold, safe to lazy load -->
<img src="partner-logo.webp" alt="Partner" width="200" height="80" loading="lazy">
<!-- Hero image: lazy-loading delays visible content -->
<img src="hero.webp" alt="Welcome banner" width="1200" height="600" loading="lazy">
Remove or defer images inside hidden containers
When images exist inside elements toggled by JavaScript or hidden by CSS, they should not download until the container becomes visible.
<!-- Use a placeholder and swap src when modal opens -->
<div id="modal" style="display: none;">
<img data-src="full-image.webp" alt="Detail view" width="800" height="600">
</div>
<script>
document.getElementById('open-modal').addEventListener('click', () => {
const modal = document.getElementById('modal');
modal.style.display = 'block';
const img = modal.querySelector('img[data-src]');
img.src = img.dataset.src;
img.removeAttribute('data-src');
});
</script>
<!-- Image downloads immediately even though modal is hidden -->
<div id="modal" style="display: none;">
<img src="full-image.webp" alt="Detail view" width="800" height="600">
</div>
Limit carousel images to one eager load
Carousels with multiple slides should load only the active slide eagerly and defer the rest.
<div class="carousel">
<img src="slide1.webp" alt="Slide 1" width="1200" height="600">
<img src="slide2.webp" alt="Slide 2" width="1200" height="600" loading="lazy">
<img src="slide3.webp" alt="Slide 3" width="1200" height="600" loading="lazy">
</div>
<!-- All three slides download at full weight on initial load -->
<div class="carousel">
<img src="slide1.webp" alt="Slide 1" width="1200" height="600">
<img src="slide2.webp" alt="Slide 2" width="1200" height="600">
<img src="slide3.webp" alt="Slide 3" width="1200" height="600">
</div>
Known Limitations
- Single Page Applications (SPAs): frameworks like React, Vue, and Angular dynamically inject images after initial render, meaning the viewport check at DOMContentLoaded may not reflect the final image positions. Lazy loading must be configured at the component level.
- Shadow DOM: images inside shadow roots are not visible to standard DOM queries from the page context. Audit tools may miss or incorrectly classify these images. Note: SiteLint supports shadow DOM.
- Iframes: images inside cross-origin iframes cannot be inspected from the parent page due to same-origin policy. Each iframe must be audited independently.
- Dynamic content loading: infinite scroll, AJAX-loaded galleries, and dynamically rendered grids produce images after initial page load, making static viewport analysis unreliable.
- CSS-driven visibility: the rule cannot detect visibility controlled by CSS custom properties, media queries, or complex selector chains that toggle display indirectly.
- Web Components and custom elements: images rendered inside custom element internals may not be exposed to the document-level query selectors used by this rule.
Resources
- MDN – Lazy loading
- web.dev – Lazy loading images and video
- Chrome Developers – Native lazy loading
- WHATWG – The loading attribute for img
Rule
- Audit: performance
- Standard: SiteLint
- Level: Best practices
- Success Criteria: N/A
- Rule ID: invisible-image-loaded