Overview
Responsive images ensure your website delivers optimally-sized images to every device, reducing page load times and bandwidth usage. The ButterCMS Image API makes this easy through URL-based transformations.Why responsive images matter
- Performance: Smaller images load faster on mobile devices
- Bandwidth: Save data for users on limited connections
- SEO: Google rewards fast-loading pages
- User Experience: Images display correctly across all screen sizes
Basic implementation
Using srcset
Thesrcset attribute lets browsers choose the best image size:
Understanding srcset and sizes
| Attribute | Purpose |
|---|---|
src | Fallback for browsers that don’t support srcset |
srcset | List of available image URLs with width descriptors |
sizes | Media conditions mapping viewport widths to image widths |
Common patterns
Full-width hero image
Blog Post featured image
Card grid image
Using the picture element
For art direction (different crops for different devices):Framework examples
React component
Vue component
Next.js with next/image
WebP with fallback
Serve WebP to supported browsers with JPEG fallback:Helper functions
JavaScript utility
Best practices
Use Appropriate Sizes
Don’t serve 4K images for thumbnails. Match image sizes to display sizes.
Lazy Loading
Add
loading="lazy" for images below the fold.WebP When Possible
WebP offers 25-35% smaller files than JPEG at similar quality.
Test Performance
Use Lighthouse or WebPageTest to verify image optimization.
Recommended breakpoints
| Device Type | Typical Width | Suggested srcset widths |
|---|---|---|
| Mobile | 320-480px | 400w, 600w |
| Tablet | 768-1024px | 800w, 1000w |
| Desktop | 1200-1920px | 1200w, 1600w, 1920w |
| Large Display | 2560px+ | 2400w |
Next steps
Image Transformations
All transformation options
Security
Secure your images
Performance
CDN optimization
Media Field
Working with media fields