Why doesn't src inside <picture> element load?

121 views Asked by At
<picture>
  <source type="image/webp" srcset="images/me.webp">
  <img id="avatar" src="images/me.webp" alt="Me">
</picture>

When I use the picture element, the browser(chrome) doesn't load the image with the other resources. However, when I replace <picture> with only <img> element it works fine:

<img id="avatar" src="images/me.webp" alt="Me">

Why is that happening?

2

There are 2 answers

1
alb3rtobr On

Your code will load the me.webp image if the browser supports its. If not, the jpg image will be shown (which works). Chrome 67 supports webp format, so the only issue I can figure out is that me.webp is not in the images folder.

1
Desmond Mullen On

AFAIK, <picture> is used when you want multiple possible images to use in a responsive design. The <img> at the end is the fallback. It sounds like images/me.webp isn;'t working.

Unless you are really making use of <picture>, use <img>.