17

I know this is a new format for images, but I don't know how to show it in HTML.

Does anyone know how I can do that? Which browsers can show this image format besides chrome?

sample-webp-image.webp

KyleMit
  • 30,350
  • 66
  • 462
  • 664
ttrasn
  • 4,322
  • 4
  • 26
  • 43

2 Answers2

45

You use webp like any image:

<img src="img.webp" />

However since it's not always supported (see http://caniuse.com/#feat=webp), you can use this to set a fallback:

<picture>
  <source srcset="img.webp" type="image/webp">
  <source srcset="img.jpg" type="image/jpeg"> 
  <img src="img.jpg">
</picture>
Sveta
  • 1,041
  • 13
  • 22
4

What if it doesn't find the image for the specified path, how can I show a no picture image in that case, something similar to this:

<img src="img.jpg" onerror="this.src = 'nopicture.gif';"/>
Gustavo
  • 41
  • 3
  • 2
    `onerror` is deprecated ([source](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#browser_compatibility)). – Sven May 24 '21 at 15:30