All formats

WebP image format

Full nameWebP
Extensions.webp
MIME typeimage/webp
Typeraster image, lossy (VP8) or lossless (VP8L), alpha, animation
Starts with52 49 46 46 xx xx xx xx 57 45 42 50 (RIFF, 4-byte size, WEBP)
SpecificationRFC 9649: WebP Image Format
Maintained byGoogle (libwebp), IETF (RFC 9649)
Licenseopen, royalty-free (Google's patent grant for VP8)
Maximum size16383 x 16383 pixels

WebP is an image format for the web. One format covers photos (lossy compression based on the VP8 video codec), graphics (a separate lossless codec), transparency and animation. Lossy WebP files are typically 25-35% smaller than JPEG at the same visual quality, and lossless WebP files are about 25% smaller than PNG.

All current browsers display WebP, and Windows, macOS, Android and iOS open it natively. It replaces JPEG, PNG and animated GIF on websites. For the best compression of photos and HDR, AVIF and JPEG XL do better.

When to use WebP#

File structure#

A WebP file is a RIFF container, the same container as WAV and AVI. It starts with a 12-byte header followed by chunks. All integers are little-endian.

52 49 46 46               "RIFF"
24 1A 00 00               file size - 8 = 6692
57 45 42 50               "WEBP"
56 50 38 20               chunk type "VP8 " (lossy)
18 1A 00 00               chunk size: 6680
30 B2 00 9D 01 2A         VP8 frame tag, start code 9D 01 2A
00 01 C8 00               width 256, height 200 (14 bits each + 2-bit scale)
...                       VP8 bitstream

Every chunk has the same layout:

Field Size Description
FourCC 4 bytes chunk type, e.g. VP8 (with a trailing space), VP8L, VP8X
Size 4 bytes size of the payload, little-endian
Payload Size bytes chunk data, padded with one 0 byte if Size is odd

There are 3 layouts:

Layout First chunk Contents
simple lossy VP8 one VP8 key frame, no alpha, no metadata
simple lossless VP8L one lossless image, alpha allowed
extended VP8X flags and canvas size, then optional ICC, animation, alpha, Exif and XMP chunks

Chunks#

Chunk Purpose
VP8 lossy image data: a VP8 key frame (RFC 6386). YUV 4:2:0, 8 bits
VP8L lossless image data. Starts with byte 0x2F, then 14 bits width-1, 14 bits height-1, 1 bit alpha-is-used, 3 bits version
VP8X extended header: 1 byte of flags (ICC, alpha, Exif, XMP, animation), 3 reserved bytes, 24-bit canvas width-1, 24-bit canvas height-1
ICCP ICC color profile. Must come right after VP8X
ANIM animation parameters: background color (BGRA) and loop count (0 = forever)
ANMF one animation frame: X/2 and Y/2 offset, width-1, height-1, duration in ms (24 bits each), blending and disposal flags, then the frame’s ALPH + VP8 or VP8L chunks
ALPH alpha channel for a lossy VP8 image: raw or compressed with the lossless codec, with an optional prediction filter
EXIF Exif metadata
XMP XMP metadata

Order in an extended file: VP8X, ICCP, ANIM, then the image (ALPH + VP8, or VP8L) or the ANMF frames, then EXIF and XMP. Readers must skip chunks they don’t know.

Lossy compression (VP8)#

Lossy WebP is a single key frame of the VP8 video codec. The image is converted to YUV with 4:2:0 chroma subsampling, split into 16x16 macroblocks, predicted from neighboring blocks, transformed with a 4x4 DCT-like transform, quantized and coded with a boolean arithmetic coder. A loop filter reduces block edges. Encoders split the image into up to 4 segments with different quantizers.

Because chroma is subsampled, thin red or blue lines and colored text get blurry. libwebp’s -sharp_yuv option reduces this.

Lossless compression (VP8L)#

The lossless codec works on ARGB pixels. Before entropy coding it applies up to 4 transforms: predictor (14 prediction modes per block), color transform (decorrelates R, G, B), subtract green, and color indexing (a palette of up to 256 colors, with pixel bundling for 2, 4 or 16 colors). Pixels are then coded with LZ77 backward references, a color cache and Huffman codes.

Animation#

An animated file has the VP8X animation flag, one ANIM chunk and one ANMF chunk per frame. Each frame is a rectangle on the canvas and can be lossy or lossless independently. Disposal (keep, or clear to background) and blending (alpha-blend or overwrite) work like GIF’s.

Converting to and from WebP#

libwebp includes command-line tools: cwebp (encode), dwebp (decode to PNG), gif2webp, img2webp (animation), webpmux (edit chunks) and webpinfo (print chunks).

Shell
cwebp -q 80 photo.jpg -o photo.webp          # lossy, quality 0-100
cwebp -lossless -z 9 logo.png -o logo.webp   # lossless, maximum effort
cwebp -q 80 -sharp_yuv -metadata icc in.png -o out.webp
dwebp photo.webp -o photo.png
gif2webp -lossy -q 70 anim.gif -o anim.webp
webpinfo -summary photo.webp                 # list chunks and check the file

Quality 75-85 is a good default for photos. -near_lossless 60 gives lossless-like quality for graphics in smaller files.

Specifications and documentation#

Software that opens WebP files#

SoftwareWindowsmacOSLinuxWebCanNotes
SumatraPDF✓viewfree, open source; also opens WebP inside comic book archives
Web browsers✓✓✓✓viewChrome, Edge, Firefox, Safari; animation and alpha. Also on Android and iOS
Microsoft Photos✓viewbuilt into Windows; uses the Webp Image Extensions codec
Paint✓view, edit, createbuilt into Windows 11
macOS Preview✓view, convertbuilt into macOS 11 and later
GIMP✓✓✓view, edit, create, convertfree, open source; animated WebP as layers
Krita✓✓✓view, edit, createfree, open source
Paint.NET✓view, edit, create, convertfree
Adobe Photoshop✓✓view, edit, create, convertcommercial; native WebP since version 23.2
IrfanView✓view, convertfree for non-commercial use, needs the plugins package
XnView MP✓✓✓view, convertfree for private use
ImageMagick✓✓✓convert, createcommand line, open source
libwebp tools✓✓✓convert, createcwebp, dwebp, gif2webp, webpmux, webpinfo
Squoosh✓convertcompare quality settings in the browser
Photopea✓view, edit, create, convertfree, runs in the browser

Libraries#

Open-source libraries that read and write WebP. See all WebP libraries for a comparison.

C/C++libwebp
C#ImageSharp, Magick.NET, SkiaSharp
JavaTwelveMonkeys, webp-imageio
Gogen2brain/webp, x/image/webp
PythonOpenCV, Pillow
Rubyruby-vips
Rustimage, image-webp, webp
PHPGD, Imagick