Lazy loading is a web engineering technique that delays the loading of non-critical resources until they are likely to be needed. It is commonly used for images, iframes, videos, embedded media, and application components that begin outside the visible portion of a page.

The central idea is simple: a browser does not always need every resource immediately. By prioritizing the content required for the initial view, a page may use less bandwidth, complete fewer early requests, and become usable sooner. However, lazy loading is not automatically beneficial everywhere. Effective implementation depends on understanding which resources are critical, when deferred loading should begin, and how the decision affects users, browsers, accessibility tools, and search systems.

What is lazy loading?

Lazy loading is the practice of postponing a resource request or initialization step until the resource approaches the point where it will be used. Instead of loading every page element during the initial request cycle, the browser or application loads selected resources later.

For example, a long article may contain twenty images, while only one or two appear in the visitor’s initial viewport. Loading all twenty immediately can consume network bandwidth and compete with the page’s primary content. Lazy loading allows the images farther down the page to wait until the reader scrolls toward them.

The resources are still part of the page. The difference is when the browser retrieves or activates them.

Lazy loading can apply to:

  • Images below the initial viewport
  • Third-party iframes and embedded media
  • Videos and video poster resources
  • Maps, social embeds, and interactive widgets
  • JavaScript modules used only after an interaction
  • Application routes or components not needed during startup
  • Data requested only when a particular interface becomes active

Although these techniques share a deferred-loading principle, they are not implemented in exactly the same way. Native image loading, dynamic JavaScript imports, deferred data requests, and delayed media initialization each participate in different parts of the browser and application lifecycle.

How lazy loading changes the request lifecycle

When a browser receives an HTML document, it parses the markup, discovers referenced resources, and decides which requests to make. Images, stylesheets, scripts, fonts, and embedded documents may all enter the browser’s loading process.

Without a deferral mechanism, a resource discovered in the document is generally eligible to be requested as the browser processes the page. Browsers still apply their own prioritization rules, but a large number of eligible resources can compete for network capacity, processing time, and memory.

Lazy loading changes that sequence for selected resources:

  1. The browser or application discovers the resource.
  2. The resource is identified as non-critical for the initial view.
  3. Its request or initialization is postponed.
  4. The browser monitors factors such as viewport proximity, user interaction, or application state.
  5. The resource is requested before or when it is expected to become useful.
  6. The loaded content is decoded, rendered, or activated.

Modern browsers often begin a lazy-loaded request before the element actually enters the viewport. This provides time for the resource to arrive before the user reaches it. The exact loading threshold may vary according to browser behavior, connection conditions, resource type, and other implementation details.

Lazy loading therefore does not always mean “wait until the element becomes visible.” A more accurate mental model is “delay the resource until the browser determines that its use is approaching.”

Eager loading versus lazy loading

Eager loading retrieves a resource as part of the page’s early loading activity. Lazy loading delays that work. Neither strategy is universally better.

Loading strategy Common use Primary consideration
Eager loading Primary images, logos, navigation assets, and immediately visible content The resource should be available early and may affect the initial rendering experience
Lazy loading Below-the-fold images, embeds, secondary media, and optional interface components The resource can wait without reducing the usefulness of the initial page

A useful loading strategy begins by separating critical resources from non-critical resources. Critical resources support the initial content, layout, navigation, or primary task. Non-critical resources may still be valuable, but they do not need to compete for attention during the earliest stage of loading.

This distinction is closely related to the critical rendering path: the sequence of work required for a browser to convert HTML, CSS, JavaScript, and other resources into visible content.

Native browser lazy loading

Modern HTML provides a loading attribute for images and iframes. This allows authors to indicate whether a compatible browser should load a resource eagerly or defer it.

Lazy-loading an image

<img
	src="/images/workshop-interior.jpg"
	alt="A finished workshop with built-in storage"
	width="1200"
	height="800"
	loading="lazy">

Lazy-loading an iframe

<iframe
	src="https://example.com/embedded-map"
	title="Map showing the project location"
	width="800"
	height="600"
	loading="lazy">
</iframe>

Native lazy loading delegates timing decisions to the browser. The browser can account for viewport distance, network conditions, and its own resource scheduling behavior without requiring a custom scroll event handler.

The attribute has two commonly used values:

  • loading="lazy" indicates that loading may be deferred until the resource approaches likely use.
  • loading="eager" indicates that the resource should be loaded without intentional viewport-based deferral.

Omitting the attribute generally leaves the resource under the browser’s normal loading behavior. Native lazy loading is often the most maintainable starting point for conventional images and iframes, but it does not replace the need to classify resources correctly.

CSS background images do not use the HTML loading attribute. They are discovered through CSS and require a different loading strategy if deferral is necessary.

Implementation approaches

Lazy loading can occur at several layers. The appropriate approach depends on the resource and the architecture of the website.

Native HTML attributes

For ordinary images and iframes, native browser support is usually the simplest approach. It requires little code, follows the browser’s scheduling model, and avoids unnecessary JavaScript dependencies.

Intersection Observer

The JavaScript IntersectionObserver interface allows an application to detect when an element approaches or intersects a defined viewport area. It can be useful when a project needs behavior beyond native image or iframe loading.

Common uses include:

  • Initializing an interactive map near the viewport
  • Replacing a video placeholder with an active player
  • Loading a custom application component
  • Requesting data as a reader approaches a section
  • Supporting resource types without native lazy-loading controls

A root margin can trigger loading before an element becomes visible, giving the resource time to arrive. The appropriate distance depends on resource size, expected connection quality, and how disruptive late loading would be.

Interaction-based loading

Some resources do not need to load until a person expresses an intention to use them. A video player might initialize after its play control is activated, or a complex editor might load after the user opens an editing panel.

This can avoid unnecessary work more effectively than viewport-based loading, especially for optional third-party tools. The initial control should remain understandable and keyboard accessible.

JavaScript code splitting

Web applications can divide JavaScript into smaller modules and load particular modules only when required. Dynamic import() is one method for doing this.

Code splitting is related to lazy loading, but it introduces application-level concerns such as error handling, loading states, route transitions, and dependency management. The technique should simplify initial delivery without making later interactions unreliable.

Placeholders and delayed media

Large videos, maps, and third-party embeds are sometimes represented initially by a lightweight image or accessible control. The full resource is created after an interaction or when it approaches the viewport.

A placeholder should communicate what it represents. It should not create an inaccessible empty region or conceal the purpose of an interactive element.

Potential performance benefits

When applied to suitable resources, lazy loading can improve several parts of the loading experience.

Fewer initial network requests

Deferring below-the-fold resources reduces the number of requests competing during the initial page load. This can be particularly useful on media-heavy pages and slower connections.

Lower initial data transfer

A visitor may never scroll through an entire page. Deferring unused images, videos, or embeds can prevent those resources from being transferred at all during that visit.

Reduced decoding and rendering work

Downloading is only one part of resource handling. Images may need to be decoded, scripts executed, and embedded documents rendered. Delaying non-critical resources can reduce early processing and memory use.

More capacity for primary content

When secondary resources wait, the browser can devote more of its early network and processing capacity to the document, styles, fonts, scripts, and media needed for the initial view.

These benefits are contextual. A short page with two small images may gain little from lazy loading. A long article, product catalog, image gallery, or page containing several third-party embeds may benefit substantially.

Lazy loading works alongside broader website performance practices. It does not replace image compression, responsive image delivery, efficient code, appropriate browser caching, or careful management of third-party resources.

When eager loading is the better choice

A resource should not be lazy-loaded merely because the option exists. Deferring an important resource can make a page feel slower even if it reduces the initial request count.

Lazy loading is usually inappropriate for:

  • The primary image or hero image visible when the page opens
  • An image likely to become the page’s Largest Contentful Paint element
  • Logos and essential navigation imagery
  • Small resources needed immediately for layout or understanding
  • Content that must be present for printing, export, or another defined workflow
  • Resources whose late arrival would create a disruptive interface shift

Lazy-loading a prominent image can delay its request because the browser must first discover that it has been marked for deferral and then determine when to retrieve it. For a likely Largest Contentful Paint image, eager loading—and in some cases an appropriate resource priority signal—may provide a better result.

Overuse can also create a sequence in which content repeatedly appears just after the user reaches it. This saves early bandwidth but produces a visibly unfinished page during scrolling. The goal is not to delay as much as possible. It is to schedule resources according to their actual role.

Preserving layout stability

Lazy-loaded content should have space reserved before it arrives. Without known dimensions, the browser may initially allocate little or no room for an image or iframe. When the resource loads, surrounding content can shift.

For images, include accurate width and height attributes or define a reliable CSS aspect ratio. The browser can then calculate the resource’s proportions before downloading it.

<img
	src="/images/remodeled-kitchen.jpg"
	alt="Remodeled kitchen with oak cabinets and a central island"
	width="1600"
	height="1067"
	loading="lazy">

The displayed size may still be responsive. The dimensions provide an intrinsic aspect ratio rather than requiring the image to appear at its full file size.

Responsive image techniques can also help browsers select a suitably sized file. URLMD’s technical guidelines for images provide additional context for image dimensions, alternative text, formats, and delivery.

Accessibility and SEO considerations

Accessibility

Lazy loading does not remove the need for semantic HTML or accessible alternatives. Images still need appropriate alt text, and iframes still need descriptive titles. Interactive placeholders must be keyboard operable and expose understandable labels to assistive technologies.

Loading behavior should also avoid creating confusion. If content takes time to appear, a meaningful loading state may be necessary. If loading fails, the interface should preserve access to the surrounding content and provide a reasonable recovery path.

Content should not depend exclusively on a fragile scroll listener or pointer interaction. Native HTML and progressive enhancement can help maintain a functional baseline when JavaScript is unavailable or fails.

For broader accessibility context, see Understanding WCAG.

SEO and content discovery

Native lazy-loaded images and iframes remain represented in the HTML, which gives browsers and retrieval systems a clear resource reference. Custom JavaScript implementations require more care.

Important content should not exist only after an ambiguous user action or depend on scrolling behavior that an automated renderer may not reproduce. If an image is meaningful to the page, its source, alternative text, dimensions, and surrounding context should be expressed clearly in the document whenever practical.

Lazy loading is not a substitute for crawlable links, semantic markup, descriptive text, or a coherent document structure. It is a resource scheduling technique rather than a content organization strategy.

How to evaluate lazy loading

Implementation should be evaluated through observation rather than assumed to be beneficial. Browser developer tools can show when requests begin, how much data is transferred, which resources receive early priority, and whether content shifts as deferred resources appear.

Use the Network panel

Open the browser’s developer tools, select the Network panel, and reload the page. A correctly deferred image should not necessarily appear among the earliest requests when it begins well below the viewport. Scrolling toward it should cause its request to begin.

Network throttling can help reveal whether a resource begins early enough to appear naturally or arrives too late on slower connections.

Inspect performance traces

A browser performance trace can show resource timing, rendering activity, layout changes, and main-thread work. This helps distinguish a genuine improvement from a change that merely moves processing to a later and less convenient moment.

Test different page positions and viewport sizes

An image that begins below the fold on a phone may be visible immediately on a large desktop display. Templates should be tested across realistic viewport sizes rather than classified according to one screen.

Check the rendered HTML

CMS platforms, themes, plugins, and optimization tools may alter image attributes. Inspect the rendered element to confirm which resources are actually marked as lazy, whether dimensions are present, and whether a prominent image has been deferred unintentionally.

Evaluate the experience, not only the request count

A lower initial transfer size is useful only when the page remains understandable and responsive. Watch for blank spaces, delayed primary images, shifting content, late-loading controls, and resources that fail when JavaScript is blocked.

Lazy loading in WordPress and other content management systems

Modern content management systems often add native lazy-loading attributes automatically. WordPress core, themes, page builders, image plugins, and performance tools may all participate in the final markup.

This convenience can reduce implementation work, but it also makes review important. Multiple layers may attempt to manage the same image, or a general rule may affect a resource that should load eagerly.

When reviewing a WordPress implementation, consider:

  • Whether the featured or primary image is loaded eagerly
  • Whether below-the-fold images receive loading="lazy"
  • Whether image dimensions or aspect ratios reserve layout space
  • Whether responsive srcset and sizes values remain correct
  • Whether plugins replace native behavior with unnecessary JavaScript
  • Whether iframes, videos, galleries, and third-party embeds behave consistently
  • Whether optimization remains functional when a plugin is disabled or updated

The final HTML delivered to the browser is more informative than a checkbox in an administrative interface. CMS settings describe intent; rendered markup and browser behavior show the actual implementation.

Lazy loading as an engineering decision

Lazy loading is most useful when treated as part of resource prioritization. A page has limited early network and processing capacity. The engineering task is to decide which resources deserve that capacity immediately and which can wait without diminishing the experience.

A durable strategy usually follows three principles:

  1. Load primary content early. Resources required for the initial view or primary task should not be delayed without a clear reason.
  2. Defer secondary work thoughtfully. Below-the-fold media, optional embeds, and inactive components are stronger candidates for lazy loading.
  3. Measure the result in context. Test resource timing, layout stability, accessibility, and real interaction rather than relying on the presence of a particular attribute.

Used carefully, lazy loading can reduce unnecessary work and help important content arrive with less competition. Used indiscriminately, it can postpone the very resources a visitor needs. Its value comes from matching loading behavior to the structure and purpose of the page.

Frequently asked questions

Does lazy loading make every website faster?

No. It is most useful when a page contains substantial non-critical media or components outside the initial viewport. Short, lightweight pages may see little benefit, while incorrectly deferring primary content can make a page appear slower.

Should the main image be lazy-loaded?

Usually not when the image is visible immediately or is likely to be the page’s Largest Contentful Paint element. Primary imagery generally benefits from early discovery and loading.

Does loading="lazy" wait until an image enters the viewport?

Not necessarily. Browsers commonly begin loading before the image becomes visible. The distance and timing are controlled by browser behavior and may vary according to conditions.

Is JavaScript required for lazy loading?

Not for standard images and iframes in modern browsers. Native HTML lazy loading works through the loading attribute. JavaScript remains useful for custom components, interaction-based loading, and resources that do not support the native attribute.