Picture Responsive Srcset Art Direction
Serve responsive images with art direction using the picture element and multiple source tags with media queries.
Code
<picture>
<source
media="(max-width: 768px)"
srcset="mobile.webp 480w, mobile-hd.webp 960w"
sizes="100vw"
type="image/webp"
/>
<source
media="(min-width: 769px)"
srcset="desktop.webp 1280w, desktop-hd.webp 2560w"
sizes="(max-width: 1024px) 100vw, 50vw"
type="image/webp"
/>
<img src="fallback.jpg" alt="Hero image" loading="lazy" />
</picture>Report a problem with this exampleOpens a pre-filled issue on GitHub.