I have an example with code directly copied from the MDN, except with my own image URLs instead:
<picture>
<source srcset="/images/site/logo.webp" type="image/webp" />
<img src="/images/site/logo.png" alt="logo" />
</picture>
Both images ("logo.webp" and "logo.png") work when I browse directly to them. However, when I inspect the above code in my browser, the inspector focuses on the <img>
tag, not the <source>
. If I then delete the <img>
, the image itself disappears from the page ... even though you'd expect it to fall back to the <source>
.
It really seems like my <source>
isn't even being used, but I don't understand why. Its corresponding image does work (I can even put the .webp
path into the <img>
tag, and it displays just fine).
What am I not understanding here about <picture>
and <source>
?
EDIT: Even if I change the HTML itself to the full URL of the PNG file (not even the WebP one), it still doesn't display anything:
<picture>
<source srcset="http://localhost:3000/images/site/logo.png">
</picture>
Shouldn't a single picture
/source
tag be enough to display an image (again, with a path that works perfectly fine in an <img>
tag)? Or am I misunderstanding <picture>
somehow?