WebP image format
| Full name | WebP |
|---|---|
| Extensions | .webp |
| MIME type | image/webp |
| Type | raster image, lossy (VP8) or lossless (VP8L), alpha, animation |
| Starts with | 52 49 46 46 xx xx xx xx 57 45 42 50 (RIFF, 4-byte size, WEBP) |
| Specification | RFC 9649: WebP Image Format |
| Maintained by | Google (libwebp), IETF (RFC 9649) |
| License | open, royalty-free (Google's patent grant for VP8) |
| Maximum size | 16383 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#
- Use for photos and graphics on websites: smaller than JPEG and PNG, supported everywhere.
- Use instead of animated GIF: lossy or lossless animation with full alpha, often 5-10 times smaller.
- Use for images with transparency where PNG is too large: lossy WebP keeps a separate alpha channel.
- Avoid for print, archiving and editing masters: lossy WebP is limited to 8-bit 4:2:0 color, which blurs fine color detail.
- Avoid for images larger than 16383 pixels on a side or for HDR / high bit depth: use AVIF, JPEG XL, PNG or TIFF.
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).
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#
- RFC 9649: WebP Image Format (IETF, 2024): the container, lossless bitstream and the
image/webpmedia type - WebP Container Specification (Google)
- WebP Lossless Bitstream Specification (Google)
- RFC 6386: VP8 Data Format and Decoding Guide: the lossy bitstream
- WebP developer site: FAQ, compression studies, cwebp/dwebp documentation
- libwebp source repository
- WebP on Wikipedia
Software that opens WebP files#
| Software | Windows | macOS | Linux | Web | Can | Notes |
|---|---|---|---|---|---|---|
| SumatraPDF | ✓ | view | free, open source; also opens WebP inside comic book archives | |||
| Web browsers | ✓ | ✓ | ✓ | ✓ | view | Chrome, Edge, Firefox, Safari; animation and alpha. Also on Android and iOS |
| Microsoft Photos | ✓ | view | built into Windows; uses the Webp Image Extensions codec | |||
| Paint | ✓ | view, edit, create | built into Windows 11 | |||
| macOS Preview | ✓ | view, convert | built into macOS 11 and later | |||
| GIMP | ✓ | ✓ | ✓ | view, edit, create, convert | free, open source; animated WebP as layers | |
| Krita | ✓ | ✓ | ✓ | view, edit, create | free, open source | |
| Paint.NET | ✓ | view, edit, create, convert | free | |||
| Adobe Photoshop | ✓ | ✓ | view, edit, create, convert | commercial; native WebP since version 23.2 | ||
| IrfanView | ✓ | view, convert | free for non-commercial use, needs the plugins package | |||
| XnView MP | ✓ | ✓ | ✓ | view, convert | free for private use | |
| ImageMagick | ✓ | ✓ | ✓ | convert, create | command line, open source | |
| libwebp tools | ✓ | ✓ | ✓ | convert, create | cwebp, dwebp, gif2webp, webpmux, webpinfo | |
| Squoosh | ✓ | convert | compare quality settings in the browser | |||
| Photopea | ✓ | view, edit, create, convert | free, 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 |
| Java | TwelveMonkeys, webp-imageio |
| Go | gen2brain/webp, x/image/webp |
| Python | OpenCV, Pillow |
| Ruby | ruby-vips |
| Rust | image, image-webp, webp |
| PHP | GD, Imagick |
Related formats#
- JPEG: older lossy format, larger files, no transparency, works everywhere
- PNG: lossless with alpha, larger files than lossless WebP
- GIF: animated WebP replaces it with much smaller files and full color
- AVIF: newer, based on AV1, better compression and HDR, slower to encode
- JPEG XL: newer, lossless JPEG recompression, high bit depth