Definition
An HTML attribute used on the <img> tag to provide the browser with a list of appropriately sized images across different device pixel densities and viewport widths.
Why It Matters
Serving desktop-sized images to mobile devices is a performance crime that kills user experience and wastes bandwidth. srcset enables resolution switching, ensuring the browser downloads the most optimal file size for the current screen.
Core Concepts
srcsetwithxdescriptors:logo-2x.png 2xfor Retina displays.srcsetwithwdescriptors:photo-320.jpg 320wprovides images of different intrinsic widths.sizes: Works alongsidewdescriptors to tell the browser how wide the image renders at each breakpoint.- Browser Choice: The browser evaluates the network and screen size to select the best file—it does not download all of them.