Loading...
Loading...
Implement performant responsive images with srcset, sizes, lazy loading, and modern formats (WebP, AVIF). Covers aspect-ratio for CLS prevention, picture element for art direction, and fetchpriority for LCP optimization. Use when adding images to pages, optimizing Core Web Vitals, preventing layout shift, implementing art direction, or converting to modern formats.
npx skill4agent add oakoss/agent-skills responsive-images| Pattern | Approach | Key Points |
|---|---|---|
| Responsive sizing | | Browser selects optimal image for viewport and DPR |
| Modern formats | | AVIF saves 70%, WebP saves 50% vs JPEG |
| Art direction | | Different crops per viewport |
| LCP hero image | | Prioritize download for Core Web Vitals |
| Below-fold images | | Defer until near viewport |
| Prevent CLS | | Browser reserves space before load |
| Fixed containers | | Maintain aspect ratio in constrained space |
| Format fallback | AVIF, WebP, JPEG source order | Best compression first, universal fallback last |
| Use Case | Widths to Generate | Sizes Attribute |
|---|---|---|
| Full-width hero | 800w, 1200w, 1600w, 2400w | |
| Content width | 400w, 800w, 1200w | |
| Grid cards (3-col) | 300w, 600w, 900w | |
| Sidebar thumbnail | 150w, 300w | |
| Image Position | loading | fetchpriority | Why |
|---|---|---|---|
| Hero/LCP | | | Optimize LCP, prioritize download |
| Above fold (not LCP) | | omit | Load normally |
| Below fold | | omit | Defer until near viewport |
| Off-screen carousel | | omit | Defer until interaction |
| Format | Quality | File Size | Browser Support | Use Case |
|---|---|---|---|---|
| JPEG | Good | Medium | 100% | Photos, complex images |
| PNG | Lossless | Large | 100% | Logos, transparency |
| WebP | Excellent | Small | 96%+ | Modern browsers, photos |
| AVIF | Excellent | Smallest | 93%+ | Cutting-edge, fallback required |
| Mistake | Correct Pattern |
|---|---|
| Omitting width and height attributes on img elements | Always include |
| Lazy loading the LCP hero image | Use |
| Using density descriptors (1x, 2x) for variable-width images | Use width descriptors (400w, 800w) with a |
| Missing alt text on content images | Provide descriptive alt text; use |
| Serving only JPEG without modern format fallbacks | Use |
ExploreTaskPlan