---
name: responsive-images
description: |
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.
license: MIT
metadata:
keywords:
- responsive images
- srcset
- sizes
- lazy loading
- webp
- avif
- aspect-ratio
- CLS
- LCP
- fetchpriority
version: 1.0.0
last_updated: 2026-01-14
---
# Responsive Images
**Status**: Production Ready ✅
**Last Updated**: 2026-01-14
**Standards**: Web Performance Best Practices, Core Web Vitals
---
## Quick Start
### Basic Responsive Image
```html
```
### Hero Image (LCP)
```html
```
---
## Configuration
### Recommended Image Sizes
| Use Case | Widths to Generate | Sizes Attribute |
|----------|-------------------|-----------------|
| Full-width hero | 800w, 1200w, 1600w, 2400w | `100vw` |
| Content width | 400w, 800w, 1200w | `(max-width: 768px) 100vw, 800px` |
| Grid cards (3-col) | 300w, 600w, 900w | `(max-width: 768px) 100vw, 33vw` |
| Sidebar thumbnail | 150w, 300w | `150px` |
### Lazy Loading Rules
| Image Position | loading | fetchpriority | Why |
|----------------|---------|---------------|-----|
| Hero/LCP | `eager` | `high` | Optimize LCP, prioritize download |
| Above fold (not LCP) | `eager` | omit | Load normally |
| Below fold | `lazy` | omit | Defer until near viewport |
| Off-screen carousel | `lazy` | omit | Defer until interaction |
---
## Common Patterns
### Full-Width Responsive Image
```html
```
### Grid Card Image (3 columns)
```html
```
### Fixed Aspect Ratio Container
```html
```
**Source**: [Web.dev - Optimize CLS](https://web.dev/articles/optimize-cls)
### Don't Lazy Load LCP Images
**Problem**: Delayed LCP, poor Core Web Vitals score
```html
```
**Source**: [Web.dev - Optimize LCP](https://web.dev/articles/optimize-lcp)
### Use Width Descriptors (w), Not Density (x)
**Problem**: Browser can't choose optimal image for viewport
```html
```
**Exception**: Density descriptors are appropriate for fixed-size images like logos.
### Always Include Alt Text
**Problem**: Fails accessibility, SEO, and screen readers
```html