The Ultimate Guide to Responsive Images for Web Developers
Published in 2026 • 11 min read
You've compressed your images and converted them to WebP. You've done the hard work. But if you serve a 2000-pixel wide desktop hero image to a user on a 400-pixel wide smartphone screen, you are still wasting massive amounts of bandwidth and ruining their experience. The final piece of the image optimization puzzle is Responsive Imagery.
The Problem with Standard Images
A standard <img src="hero.jpg"> tag forces the browser to download the exact same file regardless of the device. If the image is large enough to look crisp on a 4K monitor, it will take several seconds to download on a 4G mobile connection. The browser then throws away 80% of that downloaded pixel data when squishing the image to fit the tiny mobile screen. This is incredibly inefficient.
The Solution: srcset and sizes
Modern HTML provides developers with powerful attributes to let the browser choose the most appropriate file size based on the user's screen width and pixel density (Retina displays).
1. The srcset Attribute
Instead of providing a single source, you provide a list of sources and tell the browser how wide each image file is.
<img srcset="small.webp 400w,
medium.webp 800w,
large.webp 1200w"
src="large.webp"
alt="A responsive image">
The w unit tells the browser the true pixel width of each file in your directory.
2. The sizes Attribute
Now the browser knows the file widths, but it doesn't know how wide the image will be displayed on the page until it downloads and parses all the CSS. To prevent this delay, we use the sizes attribute to give the browser a hint.
sizes="(max-width: 600px) 100vw, 50vw"
This tells the browser: "If the screen is less than 600px, the image will take up 100% of the viewport. Otherwise, it takes up 50%." The browser uses this math to instantly select the smallest adequate image from the srcset.
Art Direction: The picture Tag
Sometimes, simply resizing an image isn't enough. For example, a wide landscape hero image might crop out the main subject when squeezed onto a vertical phone screen. You need to serve a completely different, vertically-cropped image to mobile users. This is called Art Direction.
<picture>
<source media="(max-width: 799px)" srcset="hero-mobile-portrait.webp">
<source media="(min-width: 800px)" srcset="hero-desktop-landscape.webp">
<img src="hero-desktop-landscape.webp" alt="Hero banner">
</picture>
Workflow and Tooling
Creating 3 to 5 different sizes for every single image on your website manually is tedious. Professional developers use build tools (like Webpack or Vite plugins) or cloud-based image CDNs to automatically generate these variants. For manual batches, you can rely on batch processing features in tools like ImageOptima to quickly generate your required dimensions.
Conclusion
Combining responsive HTML attributes with next-gen formats like WebP guarantees that every user, whether on a 4K desktop or a 3G smartphone, receives a fast, beautiful, and tailored experience. Master srcset and watch your mobile performance scores soar.