I'm doing the MDN HTML tutorial, in the responsive images section, I came across this:
<img srcset="elva-fairy-320w.jpg 320w,
elva-fairy-480w.jpg 480w,
elva-fairy-800w.jpg 800w"
sizes="(max-width: 320px) 280px,
(max-width: 480px) 440px,
800px"
src="elva-fairy-800w.jpg" alt="Elva dressed as a fairy">
And this
<picture>
<source media="(max-width: 799px)" srcset="elva-480w-close-portrait.jpg">
<source media="(min-width: 800px)" srcset="elva-800w.jpg">
<img src="elva-800w.jpg" alt="Chris standing up holding his daughter Elva">
</picture>
What's the difference between the two? They both pick the image based on device width, right? The MDN page says the second one should be used for art direction
problems only, I don't know what that means.
When do you use the <img>
tag along with srcset
and sizes
and when do you use <picture>
along with <media>
?