
Lazy loading delays downloading images and iframes until a visitor scrolls near them, so the first screen loads faster and mobile data is not wasted on content nobody sees. Modern browsers support it natively with one attribute: loading="lazy". The golden rule is to lazy-load everything below the fold and never the hero or main image at the top, which should load immediately with fetchpriority="high". This guide shows the right markup, how WordPress handles it, how to lazy-load background images and videos, and the mistakes that make pages slower instead of faster.
- Use native
loading="lazy"on images and iframes below the first screen. - Do not lazy-load the LCP image (hero, main product photo). Give it
fetchpriority="high". - Always include
widthandheightso lazy images do not cause layout shift. - Replace heavy video and map embeds with a click-to-load preview.
Native lazy loading: the markup
<!-- Below the fold: lazy -->
<img src="gallery-3.webp" width="800" height="600"
alt="Finished kitchen project" loading="lazy" decoding="async">
<!-- Embeds below the fold -->
<iframe src="https://www.google.com/maps/embed?pb=..." width="600" height="400"
loading="lazy" title="Our office location"></iframe>
All modern browsers support loading="lazy" on images, and Chromium and Firefox and Safari support it on iframes. Older browsers simply load the image normally, so there is no need for a JavaScript fallback.
Browsers start loading lazy images before they enter the viewport, using a distance threshold that is larger on slow connections, so visitors rarely see empty boxes when they scroll at a normal speed.
The hero image: load it eagerly and early
The largest image on the first screen is usually the page's Largest Contentful Paint (LCP) element. Lazy-loading it delays LCP, because the browser waits for layout before deciding to fetch it. Mark it as important instead: Also, this matters for lazy loading images on every kind of site.
<img src="hero-1600.webp"
srcset="hero-800.webp 800w, hero-1600.webp 1600w"
sizes="100vw" width="1600" height="900"
alt="Team at work in our Karachi office"
fetchpriority="high">
If the hero is a CSS background image, the browser discovers it late. Preload it in the head:
<link rel="preload" as="image" href="hero-1600.webp"
imagesrcset="hero-800.webp 800w, hero-1600.webp 1600w" imagesizes="100vw"
fetchpriority="high">
Lazy loading images: which images to lazy-load
| Image | Lazy? |
|---|---|
| Logo in the header | No |
| Hero or banner, main product photo | No, use fetchpriority="high" |
| Images visible on the first mobile screen | No |
| Gallery, blog images further down, testimonials, footer badges | Yes |
| Product grid images beyond the first row | Yes |
| Map, YouTube and social embeds | Yes, or click-to-load |
Remember that "above the fold" is different on a phone and a desktop. A product grid showing four items in a row on desktop may show only one on mobile.
Lazy loading images: always reserve space
A lazy image without dimensions has no height until it loads, so content jumps when it appears. Keep width and height attributes on every image and use CSS height: auto for responsiveness. Our CLS guide covers this in detail. So keep this in mind whenever you work on lazy loading images.
Lazy-loading CSS background images
Native lazy loading does not work on CSS backgrounds. Use an IntersectionObserver to add a class when the section approaches the viewport:
<section class="cta-band lazy-bg">...</section>
.cta-band.is-visible { background-image: url(cta-bg.webp); }
const io = new IntersectionObserver((entries) => {
entries.forEach(e => {
if (e.isIntersecting) { e.target.classList.add('is-visible'); io.unobserve(e.target); }
});
}, { rootMargin: '300px' });
document.querySelectorAll('.lazy-bg').forEach(el => io.observe(el));
Lazy loading images: videos and YouTube embeds
A single YouTube embed downloads hundreds of kilobytes of JavaScript even if nobody presses play. Use a "facade": show the thumbnail with a play button, and load the real iframe on click. Libraries such as lite-youtube-embed do this in a few lines, and many WordPress performance plugins have a "YouTube preview image" option.
For self-hosted videos, use preload="none" and a poster image so the file is not downloaded until the visitor plays it.
Lazy loading images: lazy loading in WordPress
- WordPress adds
loading="lazy"to content images and iframes automatically since version 5.5. - Since version 6.3 it skips lazy loading for the first large image and adds
fetchpriority="high"to the likely LCP image. - Page builders and sliders sometimes override this. Check the hero's markup in the page source.
- Do not stack a JavaScript lazy-load plugin on top of native lazy loading; it adds script and can delay images further.
How to test lazy loading
- Open DevTools → Network, filter by "Img", reload and scroll. Lazy images should only appear as you scroll.
- Run PageSpeed Insights. "Largest Contentful Paint image was lazily loaded" means you lazy-loaded the hero by mistake.
- "Defer offscreen images" means some below-the-fold images are still loading eagerly.
Frequently asked questions
Does lazy loading hurt SEO?
Not with native lazy loading. Googlebot renders pages with a tall viewport and loads lazy images. Problems come from old JavaScript methods that only load images on scroll events.
Should I lazy-load images in the first slide of a slider?
No. Lazy-load only the slides after the first one.
What does decoding="async" do?
It lets the browser decode the image off the main path so it does not hold up other rendering. It is safe on most images.
Related guides: Why Website Speed Matters and How to Make Your Site Faster, How to Get Your Website on Google and 301 vs 302 Redirects.
For official guidance, see web.dev by Google.
Want faster pages?
Our speed optimization service sets up image loading, formats and caching properly. Also see how to compress images and how to convert to WebP.
Written by the ItsWebExpert team, a web design and development company in Karachi building websites, online stores and apps for businesses across Pakistan.
Ask a Question on WhatsApp