Lazy loading is the right default for most images, but when it lands on an image that should be visible on load, it works against you. A deferred hero image leaves empty space on first paint, and when that image is the Largest Contentful Paint (LCP) element, lazy loading is one of the most common reasons the LCP score is poor.
The fix depends on how the image is being deferred: a native loading attribute, a JavaScript library, a CSS background, or a CMS plugin each need a different change. This guide covers all of them, how to tell which one applies, and how to verify the result in DevTools.
loading="lazy" to loading="eager" or remove it, add fetchpriority="high" for the LCP image, and preload it in the head. Script-controlled and CSS background images need a code change instead.loading="lazy" on the img defers the download until it nears the viewport.data-src and set it on scroll.Why are images being lazy loaded?
Before you change anything, find out which mechanism is deferring the image. Removing an HTML attribute will not fix lazy loading that a script controls, and editing a script will not help an image the browser is deferring natively. Images can be lazy loaded in several ways:
- HTML attributes. The
loading="lazy"attribute tells the browser to defer downloading an image until it nears the viewport. - JavaScript libraries. Scripts such as lazysizes defer downloads using custom data attributes and the Intersection Observer API.
- Content management systems. Platforms like WordPress add lazy-loading attributes to images automatically.
- CSS background implementations. JavaScript can delay applying a background image until its container becomes visible.
Inspect the rendered HTML and the network requests first, then pick the method below that matches the cause.
Change loading="lazy" to loading="eager"
01Swap the attribute value
The simplest way to stop native browser lazy loading is to change the image's loading attribute. This HTML tells the browser to defer the image:
<img
src="/images/hero.webp"
alt="Website homepage"
loading="lazy"
>
Change it to loading="eager":
<img
src="/images/hero.webp"
alt="Website homepage"
loading="eager"
>
You can also remove the attribute entirely. Without it, the browser uses its default behavior, which is eager loading:
<img
src="/images/hero.webp"
alt="Website homepage"
>
Use eager loading for images that appear immediately when the page opens, above the fold, particularly the main hero image. Leave loading="lazy" on below-the-fold images that benefit from being deferred.
Use fetchpriority="high" for important images
02Raise the download priority
Switching loading="lazy" to loading="eager" stops the deferral, but it does not make the image the browser's highest-priority download. For an image that contributes to LCP, add the fetchpriority attribute as well:
<img
src="/images/hero.webp"
alt="Website homepage"
loading="eager"
fetchpriority="high"
width="1200"
height="600"
>
fetchpriority="high" hints to the browser that the image should receive a higher loading priority. Keep in mind that a lazy-loaded image is deprioritized no matter what, so for the LCP image the first fix is removing loading="lazy", and fetchpriority is the refinement on top. Reserve high priority for the single most important visual, and keep the width and height attributes so the page does not shift as the image loads.
Preload the image in the head
03Request it before parsing finds it
If a hero image is your LCP element and you want the browser to start fetching it as early as possible, preload it. A preload link in the <head> tells the browser to request the image before it discovers the <img> tag during parsing:
<head>
<link
rel="preload"
as="image"
href="/images/hero.webp"
fetchpriority="high"
>
</head>
For a responsive image, match the preload to the candidate the browser will choose so you do not download the wrong file twice:
<link
rel="preload"
as="image"
href="/images/hero-800.webp"
imagesrcset="/images/hero-800.webp 800w, /images/hero-1200.webp 1200w"
imagesizes="100vw"
>
Preload is the most direct way to force an early fetch, but use it only for the one image that matters. Preloading several images delays the very resource you were trying to speed up. Preload complements eager loading; it does not replace removing loading="lazy".
Stop lazy loading images with JavaScript
04Override the attribute at runtime
If you cannot edit the source markup directly, for example when a template or plugin generates it, JavaScript can change the loading behavior at runtime. This selects every natively lazy-loaded image and switches it to eager:
document.querySelectorAll('img[loading="lazy"]')
.forEach((image) => {
image.loading = "eager";
});
You can also target one specific image and raise its priority:
const heroImage = document.querySelector(".hero img");
if (heroImage) {
heroImage.loading = "eager";
heroImage.fetchPriority = "high";
}
Run this as early as possible. If the browser has already begun processing an image, changing the attribute afterward may not prevent the initial delay, so inline the script in the <head> rather than waiting for a DOMContentLoaded handler. This approach only works on images lazy loaded through the native loading attribute. If a library stores the URL in data-src, changing loading does nothing, because src is not yet set. That case is below.
Stop CSS background images from lazy loading
05Apply the background directly
CSS background images work differently from <img> elements. There is no native loading attribute for them:
.hero {
background-image: url("/images/hero.webp");
}
If a background image is loading late, a script is almost always responsible. A common pattern stores the URL in a data attribute and applies it only when the element nears the viewport:
<div
class="hero"
data-background-image="/images/hero.webp"
></div>
To load it immediately, apply the background in CSS directly and drop the deferral, or set it with JavaScript as early as possible:
const hero = document.querySelector(".hero");
if (hero) {
hero.style.backgroundImage =
'url("/images/hero.webp")';
}
Note that background images are a low-priority resource to the browser by default, which is part of why they often appear to load late even without a lazy-loading library. A hero image that must load early is better served by an <img> or a preload link than by a CSS background.
Disable lazy loading in a JavaScript library
06Opt the critical image out
Image optimization libraries such as lazysizes store the real URL in a custom attribute and assign it to src only when the image approaches the viewport:
<img
data-src="/images/example.webp"
class="lazyload"
alt="Example image"
>
To load one of these images immediately, assign the URL yourself:
document.querySelectorAll("img[data-src]")
.forEach((image) => {
image.src = image.dataset.src;
image.removeAttribute("data-src");
image.classList.remove("lazyload");
});
This is a simplified example; the exact attribute names and class depend on the library. The more reliable fix is to opt the critical image out of the library rather than override it after the fact. With lazysizes, for example, leaving src set and omitting the lazyload class excludes an image from lazy loading. Check your library's documentation for its skip or exclude option, because a library that keeps observing the image can otherwise re-apply its behavior after your script runs.
Disable automatic lazy loading in your CMS
07Force the hero to load eagerly
Content management systems and optimization plugins add lazy loading on their own. In WordPress, inspect the generated HTML rather than assuming the editor's settings reflect the final output, and look for loading="lazy" on the image you care about. WordPress adds that attribute through the wp_img_tag_add_loading_attr filter. You can intercept it to force the first content image, usually the hero, to load eagerly:
add_filter('wp_img_tag_add_loading_attr', function ($value, $image, $context) {
static $first = true;
if ($first && $context === 'the_content') {
$first = false;
return 'eager';
}
return $value;
}, 10, 3);
If a performance plugin is doing the lazy loading instead of WordPress core, disable it there: most plugins offer an "exclude" field where you add the hero image's class, filename, or URL. Avoid turning lazy loading off site-wide. Disabling it for every image increases initial page weight and makes below-the-fold images compete with the resources that matter. Exclude only the critical image.
Load the hero early. Defer the rest.
How to check whether an image is lazy loaded
After changing the implementation, confirm the image loads as expected instead of trusting that the edit worked.
- Check the rendered HTML. Inspect the image element in Chrome DevTools. If it should load immediately, confirm it uses
loading="eager"or has no lazy-loading attribute, and is not still relying ondata-src. - Check the Network tab. Open Network, filter by
Img, and reload. The hero image's request should begin early, near the other render-blocking resources, not after a scroll. - Check Largest Contentful Paint. Use the Performance panel or PageSpeed Insights to see which element is the LCP element and when it paints. Confirm the hero image's load is no longer the bottleneck.
Disabling lazy loading can help, but it is not a guarantee: image compression, server response time, and resource prioritization all feed into the LCP score.
Common mistakes when disabling image lazy loading
| Mistake | Why it backfires | Risk |
|---|---|---|
| Disabling lazy loading on every image | Below-the-fold images still benefit from being deferred, so this increases initial downloads | High |
Using fetchpriority="high" everywhere | High priority only works as a signal when it is scarce; applied widely it cancels the browser's own prioritization | High |
| Assuming CSS controls lazy loading | CSS has no native lazy-loading attribute; a late background is JavaScript or low default priority | Medium |
| Changing HTML without checking JavaScript | A library can re-apply lazy loading after load, so verify against the final rendered HTML | Medium |
| Preloading too much | Preload is for the single LCP image; preloading several resources delays the one you wanted to accelerate | Medium |
Frequently asked questions
Does CSS have a lazy loading attribute?
No. Lazy loading is controlled by the HTML loading attribute on img and iframe elements, or by JavaScript. CSS background images have no native lazy-loading option, so if one is deferred, a script is applying it.
How do I stop a single image from lazy loading?
Set loading="eager" on that one img, or remove its loading attribute. If a library controls it, assign the real src and remove the library's class or data attribute for that image only.
Should I disable lazy loading on all images?
No. Keep it on for below-the-fold images and disable it only for images that are visible on load, usually the hero or LCP image.
Will disabling lazy loading improve my LCP score?
It can, when a lazy-loaded hero image is the LCP element, because lazy loading deprioritizes it. It is not a guaranteed fix on its own; compression, server response time and preloading also matter.
What is the difference between loading="eager" and fetchpriority="high"?
loading="eager" stops the image being deferred. fetchpriority="high" raises its priority among the resources the browser is already fetching. Important LCP images often use both.
Sources: MDN Web Docs, the img loading attribute and rel=preload; web.dev, Optimize Largest Contentful Paint; WordPress developer reference, wp_img_tag_add_loading_attr.
Related reading
Eager. Prioritized. Verified.
Stopping image lazy loading is rarely one attribute. The right fix depends on how the image is deferred: HTML, a script, a library or a CSS background.
Load the important visual early, keep the rest deferred, then confirm the real loading behavior in DevTools and measure the change in Core Web Vitals.
Paint the hero