The picture element with multiple sources
The HTML5 picture element is the standard way to provide WebP with a fallback. Inside a picture element, you specify one or more source elements with type attributes indicating the image format, followed by a standard img element that serves as the fallback. The browser loads the first source whose type matches a supported format, and if none match, it falls back to the img element. For example, you can specify a source with type image/webp and a srcset pointing to the WebP file, followed by an img element pointing to the JPG or PNG file. This approach works in all modern browsers and degrades gracefully to the fallback image in older browsers. The picture element also supports media queries, which means you can combine format fallback with responsive art direction, serving different image crops for different screen sizes while still using WebP as the primary format.
Server-side content negotiation
Server-side fallback uses the HTTP Accept header to determine which formats the browser supports. When a browser requests an image, it sends an Accept header that may include image/webp if WebP is supported. Your server or CDN can inspect this header and serve the WebP version if supported, or the JPG or PNG version if not. This approach keeps your HTML clean because you only reference a single image URL, and the server handles the format selection transparently. Apache and Nginx can be configured to do this with rewrite rules based on the Accept header. Some CDNs, including Cloudflare and Fastly, support this behavior natively or through custom VCL configurations. The downside is that it requires server-side configuration and careful cache management, because caching layers must vary the cache key by the Accept header to prevent serving WebP to unsupported browsers from a shared cache.
JavaScript detection and lazy loading
For sites that use JavaScript-based lazy loading or image galleries, you can detect WebP support programmatically and set the image source accordingly. The standard detection technique creates a small WebP image in memory, attempts to decode it, and checks whether the browser reports a valid width and height. This detection can run once per page load and store the result in a variable or cookie, which subsequent image loading logic can reference. If WebP is supported, the lazy loader requests the WebP version of each image. If not, it requests the JPG or PNG version. This approach integrates well with modern JavaScript frameworks and lazy loading libraries, and it avoids the need to modify HTML markup for every image. The trade-off is that it requires JavaScript to run before images load, which can delay the initial image requests slightly and may not work for users with JavaScript disabled.
Email and non-web environments
Email clients are the most important non-web environment where WebP fallback matters. Most email clients, including Outlook, Apple Mail, and Gmail, do not reliably support WebP images in email bodies. For marketing emails, newsletters, and transactional email templates, continue to use JPG for photographs and PNG for graphics with transparency. Do not attempt to use WebP in email unless you are targeting a very narrow audience with known WebP support. Similarly, some native mobile applications, desktop software, and document editors do not support WebP. If your images are used in PDF generation, print workflows, or native app embedding, keep JPG and PNG as the primary formats and use WebP only for the web-specific delivery pipeline. The principle is to match the format to the environment: WebP for web browsers, JPG and PNG for everything else.