DEV Community

Cover image for The Competitive Image Format for Web πŸ‘‰ WebP
Anton
Anton

Posted on • Updated on

The Competitive Image Format for Web πŸ‘‰ WebP

WebP is image compression technology that creates smaller file sizes without compromising on quality

It can reduce the file size from 20% to 80% (or even more) compared to JPEG, PNG, and GIF

xwebp-vs-png-lossless-compression-1120x642.pagespeed_.ic__.ayj7ulmvj-1066x611_1.png

Β 

Key Features


πŸ”· Developer by Google in 2010

πŸ”· Open Source

πŸ”· Extension -> .webp

πŸ”· MIME type -> image/webp

πŸ”· Lossless Compression

πŸ”· Supports Animation

πŸ”· Supports Alpha Transparency

πŸ”· Used by Google, Bind, Facebook

Β 

Browser Support


βœ… Chrome >= v9 (2011 year)

βœ… Firefox >= v65 (2019 year)

βœ… Opera >= v11.5 (2011 year)

βœ… Edge >= v19 (2019 year)

βœ… Safari iOS >= v14.4 (2020 year)

βœ… Safari* >= v14 (2020 year) // Safari needs macOS 11 or later

β›” Internet Explorer* (no native support) // IE needs fallback/polyfill

Screenshot_14.jpg

Β 

How To Use


1) Using <picture> + <img> tag

<picture>
  <source srcset="img/original.webp" type="image/webp">
  <source srcset="img/fallback.jpg" type="image/jpeg"> 
  <img src="img/fallback.jpg" alt="Alt Text!">
</picture>
Enter fullscreen mode Exit fullscreen mode

Note This option is recommended, the browser will select its own supported format

2) Using <img> tag only

<img src="img/fallback.jpg" alt="Alt Text!">
Enter fullscreen mode Exit fullscreen mode

Note Only choose this option if you don't care about old browsers (like Internet Explorer)

Β 

How To Create


Google has created its own package for Linux, Windows and macOS with command-line tools that can be used to transform your existing images (PNG, GIF, JPG) to WEBP format

Link: https://developers.google.com/speed/webp/download

This package includes:

  • The libwebp library, which can be used to add WebP encoding or decoding to your programs.
  • cwebp -- WebP encoder tool
  • dwebp -- WebP decoder tool
  • vwebp -- WebP file viewer
  • webpmux -- WebP muxing tool
  • gif2webp -- Tool for converting GIF images to WebP

Usage (Windows Example)

cwebp.exe delivery_parcel.png -q 80 -o delivery_parcel.webp
Enter fullscreen mode Exit fullscreen mode
  • delivery_parcel.png - source file
  • -q 80 - quality param set to 80%
  • -o delivery_parcel.webp - output file

Online Converters

Β 

CMS & JS Frameworks Support


CMS

JS Frameworks (that has optimized image component)

  • NextJS
  • Gatsby
  • Nuxt

Β 

CDN Automatic Conversion


Some CDNs support automatic next-gen conversion of your images, like Cloudflare (although it's not a free feature and comes with a PRO plan - $20/mo)

Thanks for reading πŸ‘

Follow me on Twitter - https://twitter.com/therceman

Top comments (2)

Collapse
 
gerbosan profile image
Carlos A.

Thanks, it is a brief but well documented article. It is good to know there's this option.

Collapse
 
therceman profile image
Anton

You're welcome! Glad that you liked it :)