Building a responsive image pipeline with picture and srcset
Responsive images have been a real pain point for years. You either served a too-large image to mobile users and wasted bandwidth, or cropped aggressively and lost visual quality on the desktop. The <picture> element with srcset and sizes fixes this — with one clean HTML declaration, the browser picks the right image for the user's device.
What problem does it solve?
A single <img> can only serve one source. Every visitor gets the same bytes, regardless of screen size, pixel density, or connection speed. That means a 2× Retina display phone loads a 2× image even though its viewport is smaller than a desktop.
The picture element
Wrap your fallback <img> in <picture>, then add <source> elements above it. Each source can specify media conditions, a sizes list, and srcset variants. The browser picks the first matching source it understands.
<picture>
<source media="(min-width: 1000px)"
srcset="wide.jpg 1x, wide-2x.jpg 2x">
<img src="fallback.jpg" alt="mountain">
</picture>
Wrap it up
Responsive images aren't optional anymore. Every image you put on a page should have a plan for different widths and densities. The picture element gives you clean, declarative control over what the browser loads — no JavaScript, no external library, zero network guesswork.