How to Generate an Image URL Using Auto=Format
Based on Sanity's image transformation documentation, there isn't a built-in fallback format parameter when using auto=format.
Here's how auto=format works:
When you use ?auto=format, Sanity automatically serves the most optimized format based on the browser's Accept header:
- WebP for browsers that support it
- AVIF for browsers that support it (though this is generated asynchronously, so the first few requests might get WebP instead)
- Falls back to PNG/JPG depending on the original source image format if the browser doesn't support modern formats
The key point: The fallback is determined by your original uploaded image format, not by a parameter you can specify. If you upload a PNG, browsers that don't support WebP/AVIF will get PNG. If you upload a JPG, they'll get JPG.
Your options:
Control the fallback by choosing your upload format: Upload your images as JPG if you want JPG as the fallback format for browsers that don't support WebP/AVIF.
Use the
fmparameter explicitly: Instead ofauto=format, you can specify the format directly withfm=jpgorfm=webp, but this means you lose the automatic format selection benefit.Handle it client-side: Use picture elements with multiple source tags to specify your own fallback chain:
<picture> <source srcset="image.jpg?fm=webp" type="image/webp"> <source srcset="image.jpg?fm=jpg" type="image/jpeg"> <img src="image.jpg?fm=jpg" alt="..."> </picture>
Unfortunately, there's no single parameter like ?auto=format&fallback=jpg in Sanity's image pipeline. The fallback format is inherently tied to your source image format when using auto=format.
Show original thread6 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.