Home HTML Attributes loading HTML loading Attribute Definition
Definition and Usage The loading attribute tells the browser when to fetch an <img> or <iframe> . Use lazy for below-the-fold media to save bandwidth; use eager (or omit the attribute) for critical above-the-fold content.
It is not a global attribute, but it is essential for performance. Pair lazy images with width/height (or aspect-ratio) and meaningful alt text.
Baseline · Widely available. Native lazy loading for images is supported across modern browsers.
Do not lazy-load the LCP image. Hero / largest contentful paint images should load eagerly so they are not delayed by the lazy threshold.
Syntax
HTML Syntax <img|iframe loading ="lazy |eager ">
Applies to img and iframe (and similarly documented for related embedding cases). Default when omitted is eager-like immediate loading for images in view.
Values
Attribute Values Value Description Try it lazyDefer fetch until near the viewport Try iteagerLoad as soon as possible (default-like) Try it
Try it
Live Preview Toggle loading on a sample image. Lazy only matters when the image starts offscreen — scroll demos work best in the Try It editor.
Code
HTML Examples 1. Lazy image 2. Eager hero 3. Lazy iframe Example 1 — Lazy-Load Below-the-Fold Images Defer gallery or article images until the user scrolls near them.
<img src="/images/gallery-2.webp" alt="Workshop photo"
width="800" height="500" loading="lazy" decoding="async"> loading="lazy" on a sample image.
How It Works Set loading="lazy" for offscreen images.Include width and height to reserve space and avoid CLS.Keep useful alt text for accessibility and SEO.decoding="async" can reduce main-thread decode jank.Example 2 — Eager Hero / LCP Image Critical above-the-fold images should not wait for a lazy threshold.
<img src="/images/hero.webp" alt="Product hero"
width="1200" height="630" loading="eager" fetchpriority="high"> loading="eager" for critical media.
How It Works Use eager (or omit loading) for the primary hero.fetchpriority="high" can further prioritize the LCP candidate.Do not lazy-load the largest above-the-fold image.Optimize the file (modern formats, correct size) separately.Example 3 — Lazy iframe Embeds Defer third-party embeds until they approach the viewport.
<iframe
src="https://example.com/embed"
title="Demo embed"
width="560" height="315"
loading="lazy"
referrerpolicy="no-referrer-when-downgrade">
</iframe> See the Try It Yourself demo for a lazy iframe example with a placeholder page.
How It Works loading="lazy" delays the iframe document fetch.Always set title for accessible framing.Prefer facades for heavy third parties when possible.Sandbox / referrerpolicy as your threat model requires. Edge Cases & Pitfalls Lazy loading is a performance tool โ misuse hurts LCP and UX.
lcp Never lazy the hero Above-the-fold / LCP images should be eager.
cls Reserve space Missing width/height causes layout shift when lazy images appear.
print Print and SEO bots Some contexts may still need the resource; test critical print styles.
css Not for background-image CSS backgrounds ignore the HTML loading attribute.
Compatibility
Browser Support loading is an HTML attribute for browsers. It is not a Node.js, Deno, or Bun API.
✓ Baseline ยท Widely available
loading Native lazy loading for img is widely supported; iframe lazy is available in modern engines.
96% Global support (approx.)
Google Chrome 77+
Full support
Mozilla Firefox 75+
Full support
Apple Safari 15.4+
Full support
Microsoft Edge 79+
Full support
Opera 64+
Full support
Samsung Internet 12+
Full support
Internet Explorer No support
Not supported loading Widely supported
Bottom line: Use lazy for below-the-fold media; keep critical images eager.
Remember
Key Takeaways Role: defer or prioritize fetching for img/iframe.
Values: lazy or eager.
Hero: keep above-the-fold images eager.
Not global: element-specific, but critical for performance.
One line: loading="lazy" waits to fetch offscreen images and iframes.
Frequently Asked Questions What does the loading attribute do? On img and iframe it controls whether the browser may defer fetching until the element is near the viewport (lazy) or should load immediately (eager).
Should above-the-fold images use lazy? Usually no. Keep LCP / hero images as eager (or omit loading) so they start immediately.
Is loading a global attribute? No. It applies to specific elements such as img and iframe (and is widely used there). It is not a true global attribute.
Does lazy loading replace width and height? No. Always set dimensions (or CSS aspect-ratio) to reduce layout shift when the image arrives.
Does loading work on background-image CSS? No. It is an HTML attribute on elements, not for CSS backgrounds.
Is loading=lazy Baseline? Yes for img in modern browsers. iframe lazy support is also broad in current engines.
Next: longdesc See the deprecated longdesc attribute for long image descriptions.
longdesc tutorial → CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion