Sub topic 8
WebP: a modern all-round format
This chapter assumes you already know the difference between lossy and lossless compression, what JPEG and PNG are good at, and what a pixel dimension is. It covers what WebP does, where it beats the older formats, how to export it, and the mistakes that cause trouble.
What WebP is
WebP is an image format developed by Google and released in 2010. It was designed to replace both JPEG and PNG for web use. One format can do what previously needed several:
- Lossy compression, like JPEG, for photographs.
- Lossless compression, like PNG, for flat color, sharp edges, and screenshots.
- An alpha channel (transparency) in both modes.
- Animation, like GIF, in both modes.
The practical result is a smaller file at similar visual quality. Google's published comparisons report lossy WebP files about 25–34% smaller than JPEG at equivalent quality, and lossless WebP files about 26% smaller than PNG. Treat those numbers as typical, not guaranteed. Your results depend on the image, so measure your own files (see the chapters on compression settings and verifying exports).
Browser support
All current major browsers (Chrome, Edge, Firefox, Safari, and their mobile versions) display WebP. Safari gained support in version 14 (2020). Very old browsers and some older email clients and desktop apps still cannot open it. For ordinary web pages, WebP is safe to use. For other destinations, such as email, social media upload forms, or print workflows, check first.
How the two modes work
The two modes use different techniques internally, so they behave differently.
| Mode | Based on | Good for | Quality setting means |
|---|---|---|---|
| Lossy | Predictive coding from the VP8 video codec | Photos, gradients, complex images | Visual quality, 0 to 100 |
| Lossless | Pixel prediction, color transforms, and entropy coding | Logos, UI screenshots, flat illustrations | Effort: how hard the encoder searches for a smaller file |
In lossy mode, the encoder predicts each block of pixels from its neighbors and stores only the difference. It then discards fine detail the eye is less likely to miss. In lossless mode, nothing is discarded, so the decoded image matches the source pixel for pixel. The quality number in lossless mode does not change the picture. It changes only encoding time and file size.
Transparency in lossy mode
This is the feature designers use most. A lossy JPEG cannot have transparency. A PNG can, but photographic PNGs with transparency are very large. Lossy WebP lets you keep a soft-edged cutout of a product photo with a transparent background, with the color data compressed lossily and the alpha channel stored separately. This often produces a file far smaller than the equivalent PNG.
Watch for these edge cases:
- The alpha channel has its own quality control. In
cwebpit is set with-alpha_q(default 100, meaning lossless alpha). Lowering it can shrink the file but can make soft edges look blocky. - Fully transparent pixels may lose their hidden color values unless you ask the encoder to keep them. This rarely matters on the web, but it matters if the file is edited later.
- A drop shadow with a long, faint gradient is where compression artifacts in the alpha channel appear first. Zoom in on shadows when you check a result.
Animation
Animated WebP replaces animated GIF in most cases. It supports full 24-bit color plus alpha, where GIF is limited to 256 colors and 1-bit transparency. A typical animation is much smaller as WebP than as GIF. The trade-offs are that fewer tools can create and edit animated WebP, and some platforms do not accept it as an upload. For long clips, a video format such as MP4 or WebM is usually smaller still, but video is outside this chapter.
Limits and failure modes
- Maximum size. A WebP image can be at most 16,383 pixels on each side. This matters for very tall page screenshots.
- Chroma subsampling. Lossy WebP always stores color at half resolution in both directions (4:2:0). Fine colored detail, such as red text on a blue background or thin colored lines, can look smeared even at high quality. If this happens, try lossless WebP or PNG instead.
- Banding. Smooth gradients in lossy mode can show visible steps, especially in dark areas. Raise the quality, or add a little noise to the source.
- Repeated re-saving. As with JPEG, each lossy export from an already lossy file adds damage. Always export from your original design file or a lossless master.
- Color management. WebP can carry an embedded color profile, but treat sRGB as the target and convert before export, as described in the color and metadata chapter.
- Lossless is not always smaller. For photographs, lossless WebP is often larger than a good lossy JPEG. Pick lossless only for flat or sharp images.
Choosing WebP against its neighbors
Use WebP when a single file should serve a wide audience and you want smaller files than JPEG or PNG without changing your workflow much. Prefer other formats in these cases:
- Use SVG for icons and logos that are drawn as shapes. A vector scales to any size and is often tiny.
- Consider AVIF (next chapter) when you want the smallest possible photograph and can accept slower encoding.
- Keep a JPEG or PNG fallback when your audience may include older browsers or when the destination does not accept WebP.
Exporting WebP
Most design tools can export WebP directly. In Figma, choose WebP in the export format list for a layer or frame. Photoshop and Sketch also offer it, and Photoshop needs a recent version. If your tool does not, use the command-line encoder from Google, cwebp.
# Lossy photo, quality 80
cwebp -q 80 hero-1600.png -o hero-1600.webp
# Lossless logo with transparency, maximum effort
cwebp -lossless -z 9 logo.png -o logo.webp
# Lossy with transparency, slightly reduced alpha quality
cwebp -q 80 -alpha_q 90 product-cutout.png -o product-cutout.webpStart lossy photos at quality 75 to 85 and compare the result to the source at 100% zoom. Note that the quality numbers are not equal across formats. WebP at 80 is not the same visual quality as JPEG at 80, which is why you must look at the output.
Serving WebP with a fallback
To support browsers or tools that cannot decode WebP, offer a fallback through the picture element. The browser picks the first source it supports.
<picture>
<source type="image/webp" srcset="hero.webp">
<img src="hero.jpg" width="800" height="450" alt="Team working at a shared desk">
</picture>Because WebP is now widely supported, many teams skip the fallback for web pages and serve WebP alone. That is a decision for your team to make based on analytics for your audience. The cost of keeping a fallback is extra files to export and name.
A short decision flow
Exercise
A designer exports a product photo with a transparent background as a PNG and gets a 1.4 MB file. Which WebP settings would you try first, and what would you check afterward?
Show answer
Export as lossy WebP at quality around 80, keeping the alpha channel (for example cwebp -q 80 -alpha_q 90). Then compare file size with the PNG and view the result at 100% zoom, looking especially at soft edges and shadows for blocky alpha artifacts and at the photo for banding or smeared color. If edges look bad, raise -alpha_q to 100 or the main quality value.
Exercise
A flat illustration with thin red lines on a blue background looks smeared when exported as lossy WebP at quality 90. What is the likely cause, and what are two ways to fix it?
Show answer
Lossy WebP stores color at half resolution (4:2:0 chroma subsampling), which blurs thin colored detail even at high quality. Fix it by exporting as lossless WebP, or by using PNG. SVG is also a good choice if the illustration is made of shapes.