LQIP Generator - Learn Lazy Loading
Create tiny, blurred placeholders for images that make your site feel instantly fast. Understand how top websites achieve smooth image loading.
π What You'll Learn:
LQIP (Low-Quality Image Placeholder) is a technique where a tiny (10-20 pixel), heavily blurred version of your image loads instantly, then transitions to the full image. This eliminates jarring layout shifts and makes your site feel lightning fast!
Understanding LQIP (Low-Quality Image Placeholders)
LQIP is a performance technique used by Netflix, Medium, and Facebook. Instead of showing empty space while images load, a tiny blurred version appears instantly, creating a smooth loading experience.
How LQIP Works - The Simple Version
-
Shrink the image to ~20 pixels wide
canvas.width = 24; canvas.height = 16; -
Convert to base64 data URL
canvas.toDataURL('image/jpeg', 0.4) -
Embed directly in HTML (no extra request!)
<img src="data:image/jpeg;base64,/9j/4AAQ..."> -
Apply CSS blur and scale up
filter: blur(5px); transform: scale(1.1); -
Lazy load the real image on top
img.onload = () => fadeIn();
Why LQIP Improves Performance
Instant Visual Feedback
- No layout shift (CLS improvement)
- Immediate color and composition
- Perceived performance boost
- Better than gray boxes or spinners
Tiny Size Impact
- Only 400-800 bytes per image
- Inline in HTML (no extra request)
- Loads with initial HTML
- Works even on slow 3G
The Magic Numbers
| LQIP Size | Dimensions | File Size | Best For |
|---|---|---|---|
| Tiny | 16 Γ 10px | ~400 bytes | Hero images, backgrounds |
| Small | 24 Γ 16px | ~600 bytes | Product images, galleries |
| Medium | 32 Γ 20px | ~800 bytes | Detailed images, portraits |
| Large | 42 Γ 28px | ~1KB | Complex compositions |
π‘ Learning Tip:
The blur is crucial! A 20-pixel image looks terrible when scaled up, but add a 5px blur and suddenly it becomes a pleasant color wash that gives users immediate context about what's loading. This psychological trick makes your site feel much faster than it actually is!
Real-World Implementation
// Simple LQIP function you can use function makeLQIP(img) { // Create tiny canvas const canvas = document.createElement('canvas'); canvas.width = 24; // Tiny width canvas.height = 16; // Maintain aspect ratio // Draw and downsample const ctx = canvas.getContext('2d'); ctx.filter = 'blur(0.5px)'; // Slight blur while drawing ctx.drawImage(img, 0, 0, 24, 16); // Return base64 string (40% quality is plenty) return canvas.toDataURL('image/jpeg', 0.4); }
β Pro Implementation Tips:
- Generate LQIP during image upload, not on-the-fly
- Store the base64 string in your database
- Inline it directly in your HTML to avoid extra requests
- Use CSS blur, not canvas blur, for the final display
- Add a fade transition when the real image loads