Lazy Loading Generator
Generate production-ready lazy-loading code for images, iframes, CSS backgrounds, video and components — native loading="lazy" or IntersectionObserver, for vanilla JS, React, Next.js or Vue. Add blur-up placeholders, fade-in, decoding="async" and fetchpriority, tune rootMargin/threshold, and get the HTML, JS and CSS you need.
About this ToolHow it works, benefits & use casesTap to collapse
This generator writes production-ready code for deferring off-screen assets until the user scrolls near them. Pick what you are loading — an image, an iframe, a CSS background image, a video, or a heavy component — then choose a technique (native loading="lazy" or a scripted IntersectionObserver) and a framework target (vanilla JS, React, Next.js, or Vue). Native loading is offered only for images and iframes, the two elements that support it; everything else automatically falls back to an observer. Layer on extras: a blur-up LQIP placeholder, an opacity fade-in with a custom duration, decoding="async" and a fetchpriority hint for images, explicit width/height to reserve space, and the observer's rootMargin and threshold. Output appears live across HTML, JavaScript, and CSS tabs — only the panels a combination actually needs are shown, with React/Next.js/Vue component code emitted in the JavaScript tab. A Notes & warnings panel surfaces contextual guidance (most importantly, never lazy-load your LCP/hero asset), and curated presets jump-start common setups like blog images, infinite galleries, lazy iframes, and Next.js dynamic imports.
How to Use
- 1Pick a preset for a common setup, or build from scratch by choosing what you are loading: image, iframe, background image, video, or component.
- 2Choose a technique — native loading="lazy" (images/iframes only) or IntersectionObserver — and a framework: vanilla, React, Next.js, or Vue.
- 3Enter the asset URL and alt/title, and set width/height to reserve space; component mode needs no URL.
- 4Toggle options like blur-up LQIP, fade-in, decoding="async" and fetchpriority, and tune rootMargin/threshold for the observer.
- 5Switch between the HTML, JavaScript and CSS tabs to copy or download the generated snippet, and read the Notes & warnings panel.
Key Benefits
- Five targets in one tool — images, iframes, CSS background images, video, and components
- Two techniques (native loading="lazy" vs. configurable IntersectionObserver) with native auto-disabled where it does not apply
- Emits framework-specific code for vanilla JS, React, Next.js, and Vue from the same settings
- Rich options: blur-up LQIP, fade-in with custom duration, decoding="async", fetchpriority, width/height, rootMargin and threshold
- Live HTML / JavaScript / CSS tabs that show only the panels a given combination needs
- Contextual Notes & warnings panel flags LCP/hero mistakes, layout shift, and per-target best practices
- Curated presets (blog images, infinite gallery, lazy iframe, lazy video, Next.js Image, next/dynamic, React.lazy) plus copy/download per snippet
Common Use Cases
- Deferring below-the-fold gallery images with native lazy loading and a blur-up placeholder
- Lazy-mounting a YouTube or maps iframe so its third-party JS does not block first paint
- Loading a heavy CSS background image only as its section nears the viewport
- Fetching a video lazily with a poster image and preload="none" instead of up front
- Code-splitting a heavy component with React.lazy, next/dynamic, or Vue defineAsyncComponent
<img
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MCIgaGVpZ2h0PSIzMCI+PGZpbHRlciBpZD0iYiI+PGZlR2F1c3NpYW5CbHVyIHN0ZERldmlhdGlvbj0iNCIvPjwvZmlsdGVyPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbHRlcj0idXJsKCNiKSIgZmlsbD0iI2NiZDVlMSIvPjwvc3ZnPg=="
data-src="https://example.com/images/photo.jpg"
alt="Descriptive alt text"
loading="lazy"
decoding="async"
fetchpriority="low"
width="1200"
height="800"
class="blur-up"
onload="this.src=this.dataset.src;this.classList.add('is-loaded')"
>Notes & warnings
- Never lazy-load your LCP / hero asset. Deferring the largest above-the-fold element delays the Largest Contentful Paint and hurts Core Web Vitals — reserve lazy loading for below-the-fold content.
- Native loading="lazy" is the simplest, most robust option for images: zero JS, the browser tunes the viewport distance for you, and it degrades gracefully. Prefer it unless you need a custom placeholder/animation pipeline.
- Blur-up: ship a tiny (~1–2KB) low-quality placeholder inline, then swap in the full asset and remove the blur. It hides network latency without a layout shift.
Presets
What are you loading?
Technique
Framework
Source
Reserve space — prevents layout shift
Options
Ship a tiny blurred placeholder, then swap in the full asset
Decode off the main thread for smoother scrolling
Hint the browser how to prioritise the fetch
Native vs. IntersectionObserver
Reach for native loading="lazy" first: it ships zero JavaScript, the browser tunes the viewport distance for you, and it degrades gracefully on old browsers. It only exists for <img> and <iframe>.
Use an IntersectionObserverwhen you need control native loading can't give you — CSS background images, <video>, scripted blur-up, or a custom fade. Whatever you pick, never lazy-load your LCP / hero image: deferring the largest above-the-fold element delays Largest Contentful Paint and hurts Core Web Vitals.
Was this tool helpful?
Share Your Experience
Help others discover this tool!
Related tools
- Performance Budget CalculatorCalculate and track performance budgets for web apps
- HTML FormatterFormat and beautify HTML code
- Component Name GeneratorTurn a description into ranked, kind-aware component names with a file scaffold and a name validator (casing, collisions, clarity)
- Skeleton Screen GeneratorBuild layout-matched skeleton loaders (card/list/article/table) with shimmer/pulse/wave and a live preview
- Changelog GeneratorGenerate changelog from Git commit history
- Heroku Procfile GeneratorBuild a Heroku Procfile and matching app.json — process types, env vars, addons, dyno formation — plus a Procfile parser and audit
Native loading="lazy" is the simplest, most robust choice: it ships zero JavaScript, the browser tunes the viewport distance for you, and it degrades gracefully — but it only exists for <img> and <iframe>. The tool greys out native for backgrounds, video, and components and uses an IntersectionObserver instead. Reach for the observer when you need control native loading cannot give you, such as a custom rootMargin, scripted blur-up, or a fade-in. Pick the technique with the buttons under "Technique".
Vanilla JS, React, Next.js, and Vue. For vanilla, the HTML tab holds the markup and the JavaScript tab holds the observer script. For React, Next.js, and Vue the component code is emitted in the JavaScript tab — for example a React.lazy + Suspense component, a next/dynamic import, next/image with a blur placeholder, or a Vue defineAsyncComponent — so you copy a self-contained snippet for your stack.

