image/webp means: image/webp is the registered media type for WebP, a modern image format from Google supporting both lossy and lossless compression plus alpha transparency and animation. WebP typically produces smaller files than JPEG or PNG at comparable quality, improving page load performance. Image media types identify raster and vector graphics. The subtype selects the decoder and influences compression, transparency and animation support. Serving the right image type lets browsers pick efficient decoding paths, enables responsive srcset negotiation, and avoids the broken-image icon that appears when bytes and declared type disagree. You will encounter image/webp in contexts such as optimized web photographs and graphics; animated images replacing gif with better compression; responsive delivery negotiated via accept headers. It is commonly associated with the file extension(s) .webp. WebP enjoys broad modern browser support but very old clients may lack it. Use the picture element or Accept-based content negotiation to serve WebP with a JPEG/PNG fallback, ensuring every visitor receives a decodable image.
When you'll see image/webp
- Optimized web photographs and graphics
- Animated images replacing GIF with better compression
- Responsive delivery negotiated via Accept headers
How to handle it
When serving images, match the Content-Type to the actual encoded bytes, set long-lived cache headers for immutable assets, and provide width/height or aspect-ratio hints to avoid layout shift. Use responsive delivery (srcset, picture, or server content-negotiation) so clients receive a format they support at an appropriate resolution. Validate uploaded images by decoding them, not by trusting the extension or the client-supplied type. As a final checklist for image types: compress and resize for the display slot, serve modern formats with fallbacks, add width and height to prevent layout shift, cache immutable assets aggressively, and validate uploads by decoding rather than trusting the claimed type or extension.
Notes & gotchas
WebP enjoys broad modern browser support but very old clients may lack it. Use the picture element or Accept-based content negotiation to serve WebP with a JPEG/PNG fallback, ensuring every visitor receives a decodable image.
Examples
HTTP/1.1 200 OK
Content-Type: image/webp
Content-Disposition: inline; filename="sample.webp"
[binary image payload: the encoded bytes of a sample .webp] curl -i -H "Accept: image/webp" https://api.example.com/v1/resource # inspect the returned Content-Type const res = await fetch("/media/sample.webp", { headers: { Accept: "image/webp" } });
const blob = await res.blob(); // blob.type should be "image/webp"
const url = URL.createObjectURL(blob); // assign to img.src / audio.src / video.src
// revoke with URL.revokeObjectURL(url) when done to free memory import requests
res = requests.get("https://api.example.com/v1/resource",
headers={"Accept": "image/webp"}, timeout=30)
res.raise_for_status()
assert res.headers["Content-Type"].startswith("image/webp")
with open("sample.webp", "wb") as fh:
fh.write(res.content) # raw bytes; use stream=True for large files Frequently asked questions
Is WebP better than JPEG?
Usually yes for size: lossy WebP is often 25-35% smaller than JPEG at similar quality, and it adds transparency and animation. Provide a fallback for legacy clients that cannot decode WebP.
How do I serve WebP with a fallback?
Use the picture element with a source type=image/webp and an img fallback, or negotiate on the Accept header server-side and return the matching Content-Type.
How do browsers choose between image formats?
Through the Accept header and srcset/sizes or the picture element. The server can content-negotiate (e.g. serve WebP/AVIF to clients that accept it), and the declared Content-Type must match the bytes actually sent.
Does the file extension determine the MIME type?
No — the server declares Content-Type, and the bytes must match it. Extensions are a convenience for mapping, but a .png file served as image/jpeg, or vice versa, can render incorrectly or be rejected by strict clients.
How do I prevent layout shift when images load?
Set explicit width and height attributes (or CSS aspect-ratio) so the browser reserves space before the image arrives, and use responsive srcset/sizes to deliver an appropriately sized file for each viewport.
Try the Base64 Encoder
Encode and decode Base64 with UTF-8 and URL-safe options.