Bu makale şu anda yalnızca İngilizce olarak mevcuttur.

WebPSep 4, 20255 min read

WebP Fallbacks with Picture: A Conservative Implementation Guide

WebP support is broad enough that many teams can use it as a default web image format. Still, a conservative implementation should not assume every client, crawler, CMS preview, email tool, or embedded browser will handle every modern format the same way. The HTML picture element gives you a practical way to serve WebP while keeping a fallback image available.

The goal is not to write clever markup. The goal is to make image delivery predictable: modern browsers get the efficient file, older or constrained clients get a supported fallback, and the page keeps the same accessible text and layout behavior.

A picture snippet is only the markup layer. A production fallback guide also has to verify the generated WebP files, the fallback files, the type attributes, the rendered dimensions, the alt text source, and the cache or rewrite layer that serves the actual URLs.

Use Picture for Format Choice#

The picture element lets the browser evaluate multiple image sources and choose the first one it can use. For a simple WebP fallback, the pattern looks like this:

<picture>
  <source srcset="/images/team.webp" type="image/webp" />
  <img src="/images/team.jpg" alt="Design team reviewing a product mockup" />
</picture>

The source element offers the WebP file. The img element remains the required fallback and carries the alt text. If the browser does not use the WebP source, it can still load the JPEG.

MDN's picture element documentation is the best reference for the element's selection behavior. Google's WebP documentation gives format background.

Keep the Img Element Complete#

Do not treat the img tag as a leftover. It is still the image element in the document. It should include the attributes that matter for accessibility, layout, and loading behavior:

<picture>
  <source srcset="/images/product.webp" type="image/webp" />
  <img
    src="/images/product.jpg"
    width="1200"
    height="800"
    alt="Brown leather backpack with brass buckles"
    loading="lazy"
    decoding="async"
  />
</picture>

The fallback src should point to a real file. Avoid leaving it blank or pointing it to the same WebP file you are trying to fall back from.

Generate and Verify the File Family#

Before replacing markup, create a small set of WebP files from the same approved fallback images and keep a conversion report:

mkdir -p ./reports

getwebp ./fallback-working \
  --recursive \
  --output ./public/images \
  --json \
  --manifest ./reports/picture-webp-manifest.json \
  > ./reports/picture-webp.ndjson

Summarize the generated source-to-output map:

jq -r '
  select(.type == "convert.completed")
  | .data.results[]
  | [.status, .file, .outputPath, .originalSize, .newSize, (.error // "")]
  | @tsv
' ./reports/picture-webp.ndjson

The manifest is useful for successful output fingerprints, but the NDJSON report is still the place to review failures or truncation events. The CLI command reference documents --json and --manifest, and the JSON output guide explains the conversion events.

Do not delete the JPEG or PNG fallback files during this step. A picture implementation is only conservative if the fallback path remains real after deployment.

Combine Format Fallbacks With Responsive Sizes Carefully#

When a page also needs responsive image sizes, each format needs its own srcset:

<picture>
  <source
    type="image/webp"
    srcset="/images/hero-800.webp 800w, /images/hero-1400.webp 1400w"
    sizes="(max-width: 768px) 100vw, 1400px"
  />
  <img
    src="/images/hero-1400.jpg"
    srcset="/images/hero-800.jpg 800w, /images/hero-1400.jpg 1400w"
    sizes="(max-width: 768px) 100vw, 1400px"
    width="1400"
    height="800"
    alt="Ceramic tableware arranged on a dining table"
  />
</picture>

Keep the sizes logic aligned between formats. If WebP and JPEG use different size rules by accident, performance testing becomes confusing because the browser may download different dimensions for each format.

Do Not Break Alt Text Workflows#

Format migration should not create duplicate accessibility work. There should be one meaningful alt value on the img element, not separate descriptions for every generated file.

This matters in CMS environments. Some systems store alt text on the media record, while others store it in the page content. Before replacing image markup at scale, verify that the migration preserves the alt text source your editors use.

If a conversion plugin or build step generates picture markup automatically, inspect the output. A smaller image is not an improvement if the migration drops alt text or removes dimensions that prevented layout shift.

Test Caches and Rewrites#

Fallback markup can fail outside the HTML if the server or CDN is not configured cleanly. Common problems include:

  • WebP files generated but not uploaded
  • stale HTML pointing to deleted fallback files
  • CDN rules rewriting image URLs unexpectedly
  • incorrect Content-Type headers
  • missing Vary: Accept on server-side format negotiation
  • CMS image size variants missing for one format

After deployment, test the real production URL, not only a local build. Open the network panel and confirm which file loads, which content type is returned, and whether fallback files still exist.

For a direct WebP URL, the response should identify the file as WebP:

curl -I https://example.com/images/team.webp | grep -Ei 'content-type|cache-control|vary'

For a direct fallback URL, verify that it still returns the fallback format:

curl -I https://example.com/images/team.jpg | grep -Ei 'content-type|cache-control|vary'

If your CDN rewrites /images/team.jpg to WebP based on the Accept header, test that behavior separately from the picture markup. Header negotiation and explicit picture sources are different delivery strategies, and mixing them without tests can hide broken fallbacks.

Also test an image after clearing the CDN cache or changing the filename. A fallback strategy is only useful if the cache layer serves the same file family that the HTML now references.

Keep the Rollout Small First#

Start with one template or a limited set of high-value images. Product hero images, landing page headers, and article featured images are good candidates because they are large enough to matter and visible enough to review.

Once the markup, generation, upload, and cache behavior are stable, extend the pattern to more assets. A conservative rollout is not slow for its own sake; it prevents one image-format change from becoming a site-wide broken-image incident.

The picture element is a practical bridge. It lets teams use WebP where it helps while keeping a dependable fallback path for the rest of the web delivery stack.

Jack avatar

Jack

GetWebP Editor

Jack writes GetWebP guides about local-first image conversion, WebP workflows, browser compatibility, and practical performance checks for teams that publish images on the web.