how show webp image format in HTML (browsers)

孤人 提交于 2019-12-10 15:32:23

问题


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 browser can show this image format except chrome? sample image

Update: new version of browsers can support this format.


回答1:


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>



回答2:


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';"/>


来源:https://stackoverflow.com/questions/44918470/how-show-webp-image-format-in-html-browsers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!