WEBPery

How a WebP file is structured: the RIFF container, the WEBP FourCC, and VP8, VP8L, VP8X, ALPH, ANIM and ANMF chunks. The byte layout explained clearly.

WebP File Structure: The RIFF Container and Chunks

A WebP file is a RIFF container holding one or more typed chunks. The first 12 bytes identify the file as WebP; the chunks that follow carry the image data, alpha, animation, and metadata. Understanding this layout explains how one .webp file can be a photo, a transparent graphic, or an animation. This guide walks the byte structure.

For the format overview, see What is WebP?. For how the image data inside these chunks is compressed, see WebP Compression: How VP8 and VP8L Encoding Works.

What container format does WebP use?

WebP uses RIFF — the Resource Interchange File Format. RIFF is a generic, little-endian container that stores data as a sequence of chunks, each with a 4-character identifier and a size. The same container family holds WAV audio and AVI video.

RIFF's chunk model lets WebP extend cleanly: new capabilities become new chunk types without breaking decoders that ignore unknown chunks.

What are the first bytes of a WebP file?

Every WebP file begins with a 12-byte header: the ASCII characters RIFF, a 4-byte little-endian file size, then the ASCII characters WEBP. A decoder reads these 12 bytes to confirm the file is WebP before parsing further.

The byte layout is fixed:

OffsetBytesContent
04RIFF (FourCC)
44File size minus 8, little-endian
84WEBP (FourCC)

These leading bytes — RIFF....WEBP — are the magic number used to detect WebP regardless of file extension. They underpin the image/webp MIME type and server content detection.

What is a FourCC?

A FourCC is a four-character code that identifies a chunk's type. WebP uses FourCCs such as VP8 (note the trailing space), VP8L, and VP8X. Each chunk header pairs its FourCC with a 4-byte payload size, followed by the payload itself.

Chunks are padded to even byte boundaries. A chunk with an odd payload size gets one padding byte, keeping the structure word-aligned.

What are the three WebP file forms?

WebP has three file forms, distinguished by the chunk after the WEBP FourCC: simple lossy, simple lossless, and extended. Simple files contain a single image chunk. Extended files begin with a VP8X chunk that flags which optional features the file uses.

The three forms are:

  1. Simple lossy — a single VP8 chunk containing VP8-encoded image data.
  2. Simple lossless — a single VP8L chunk containing VP8L-encoded image data.
  3. Extended — a VP8X chunk plus any combination of alpha, animation, colour-profile, and metadata chunks.

What chunks can a WebP file contain?

A WebP file can contain image, feature, and metadata chunks. The image chunk holds the pixel data; feature chunks add alpha and animation; metadata chunks store colour profiles and EXIF or XMP data. Decoders read only the chunks they understand.

The defined chunks are:

  • VP8 — lossy image data (VP8 bitstream).
  • VP8L — lossless image data (VP8L bitstream).
  • VP8X — extended-format header; flags alpha, animation, ICC, EXIF, and XMP presence.
  • ALPH — alpha-channel data for a lossy image, compressed losslessly.
  • ANIM — global animation parameters: background colour and loop count.
  • ANMF — a single animation frame, with position, duration, and disposal method.
  • ICCP — embedded ICC colour profile.
  • EXIF — EXIF metadata.
  • XMP — XMP metadata.

The ALPH chunk is how lossy WebP keeps transparency exact — see WebP Transparency. The ANIM and ANMF chunks drive WebP Animation.

How does the VP8X chunk enable extended features?

The VP8X chunk holds a feature-flags byte plus the canvas width and height. Each flag bit declares whether the file uses an ICC profile, alpha, EXIF, XMP, or animation. Decoders read these flags to know which optional chunks to expect.

The canvas dimensions in VP8X are stored as 24-bit values, allowing a canvas up to 16,777,216 pixels per side. Individual image data remains limited by VP8 to 16,383 × 16,383 pixels.

What are the maximum dimensions of a WebP file?

WebP supports a maximum image size of 16,383 × 16,383 pixels. This limit comes from the 14-bit width and height fields in the VP8 bitstream. Images larger than this cannot be stored in a single WebP file and must be tiled or use another format.

For typical web imagery this ceiling is never reached. It matters only for very large prints, panoramas, or scientific imagery.

Where to go from here

The RIFF container is what makes WebP one format instead of three. A single chunk-based structure carries lossy photos, lossless graphics with alpha, and full animations.

What is WebP? A Complete Guide to the WebP Image Format

WebP is Google's image format with lossy and lossless compression. Learn how it works, browser support, file sizes, transparency, and animation.

WebP Transparency: Alpha Channel Support

WebP supports an 8-bit alpha channel in lossy and lossless modes. How transparency is stored, the ALPH chunk, file-size cost, and PNG comparison.

srcset and WebP: Responsive Images with Format Fallback

Use srcset and sizes to serve responsive WebP at the right resolution per device, with a JPEG fallback. Width and density descriptors explained.

How to Serve WebP Images in HTML Using the picture Element

Serve WebP with a JPEG or PNG fallback using the HTML picture element. Syntax, source ordering, art direction, and the mistakes to avoid.