srcset and sizes
srcset lists available image widths. sizes tells the browser how wide the image will display. The browser picks the best match.
This enables resolution switching without JavaScript.
srcset lists available image widths. sizes tells the browser how wide the image will display. The browser picks the best match.
This enables resolution switching without JavaScript.
<img
src="image-800.jpg"
srcset="image-400.jpg 400w,
image-800.jpg 800w,
image-1200.jpg 1200w"
sizes="(max-width: 600px) 100vw,
(max-width: 1200px) 50vw,
800px"
alt="Responsive image"
>
Use srcset+sizes for resolution switching (same content, different sizes) and <picture> for art direction.