apyhub
Cover illustration for How to Convert Images to WebP in 2026: Formats, Browser Support, and a Conversion API
Engineering

How to Convert Images to WebP in 2026: Formats, Browser Support, and a Conversion API

Originally published June 2023. Refreshed in September 2026 with current browser support, 2025 Web Almanac data, an AVIF comparison, and updated API examples.

01Introduction

WebP is an image format from Google that makes photos and graphics smaller than JPEG and PNG while keeping the same visual quality. Converting your website images to WebP reduces page weight, which speeds up loading and helps your Largest Contentful Paint (LCP) score.

If you want to convert one image right now, this request turns a PNG into WebP and returns a link to the result:

bash

· bash
curl -X POST "https://api.eu.apyhub.com/apyhub/convert-png-to-webp/url/link" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://assets.apyhub.com/samples/sample.png"}'

json

· json
{
  "data": "https://..."
}

The rest of this guide covers what WebP is, how it compares with PNG, JPEG, and AVIF in 2026, which browsers support it, how to convert images with command-line tools, code libraries, or an API, and how to serve WebP safely with fallbacks.

Try the PNG to WebP API free, no card

Table of contents

  1. What is WebP?
  2. Why image format still matters in 2026
  3. WebP vs PNG vs JPEG vs AVIF
  4. WebP browser support in 2026
  5. How to convert images to WebP
  6. Convert images to WebP with the ApyHub API
  7. How to serve WebP with a fallback
  8. When WebP files get bigger
  9. WebP conversion checklist
  10. FAQ

02What Is WebP?

WebP is an open, royalty-free image format developed by Google that supports lossy compression, lossless compression, transparency (alpha), and animation in a single format. It was designed to replace JPEG, PNG, and GIF on the web.

According to Google's WebP documentation:

  • WebP lossy compression averages about 30% more compression than JPEG without loss of image quality (WebP Lossy Study).
  • WebP lossless images are 26% smaller than PNGs (WebP Lossless and Alpha Study).
  • Animated GIFs converted to lossy WebP are 64% smaller, and to lossless WebP 19% smaller.
  • The maximum size of a WebP image is 16383 × 16383 pixels.

Technically, lossy WebP stores images as 8-bit YUV 4:2:0, and lossless WebP stores them as RGBA. That distinction matters later, when you decide which images to convert and how.

03Why Image Format Still Matters in 2026

Images are usually the largest element on a page, which makes them the main driver of LCP, one of Google's Core Web Vitals. A smaller hero image downloads faster, and the page is ready sooner.

Most of the web still hasn't made the switch. The HTTP Archive Web Almanac 2025 found that among pages whose LCP element is an image, 57% use JPG, 26% use PNG, 11% use WebP, and AVIF sits at 0.7%. Across all images on mobile pages, the 2024 Web Almanac measured JPEG at 32.4%, PNG at 28.4%, GIF at 16.8%, WebP at 12%, and AVIF at 1.0%.

The Almanac attributes the slow shift to the cost of migrating existing image pipelines and content libraries. That's the practical problem this guide addresses: converting an existing library at scale, then serving the result correctly.

See every image conversion API in the catalog

04WebP vs PNG vs JPEG vs AVIF

JPEGPNGWebPAVIF
CompressionLossyLosslessLossy and losslessLossy and lossless
TransparencyNoYesYesYes
AnimationNoAPNG onlyYesYes
Typical sizeBaselineLargest for photos~25–34% smaller than JPEG (lossy); 26% smaller than PNG (lossless)Usually smaller than WebP for photos
Encoding speedFastFastFastNoticeably slower
Browser supportUniversalUniversalAll current major browsersAll current major browsers, newer versions only
Best forUniversal fallback, emailScreenshots, UI, source filesDefault web format for most imagesLarge photos and hero images

WebP vs PNG

Use WebP for web delivery and PNG for source files and editing. Lossless WebP keeps every pixel of a PNG, including transparency, at a smaller size (26% smaller on Google's test set). Keep the PNG originals in your asset storage and serve the WebP version.

WebP vs JPEG

For photographs, lossy WebP is smaller than JPEG at comparable quality, and it also supports transparency, which JPEG can't. JPEG still has the widest support of any format, which makes it the right last-resort fallback.

AVIF vs WebP

AVIF, based on the AV1 video codec, usually compresses photographs further than WebP. Independent comparisons published in 2026 put AVIF roughly 15–30% smaller than WebP for photos at matched perceptual quality. The trade-offs are slower encoding and support limited to more recent browser versions.

The common 2026 approach is to serve AVIF first, WebP second, and JPEG or PNG last, using the <picture> element shown later in this guide. If you only add one modern format, WebP is the lower-risk choice because of its broader support and faster encoding.

What about JPEG XL?

JPEG XL compresses well and can losslessly recompress existing JPEGs, but as of early 2026 it decodes in Safari 17+ and isn't enabled by default in Chrome. For general web delivery, it isn't a replacement for WebP yet.

05WebP Browser Support in 2026

Every current major browser supports WebP. Google lists these minimum versions for lossy, lossless, and transparent WebP:

  • Google Chrome (desktop) 23+ and Chrome for Android 25+
  • Microsoft Edge 18+
  • Firefox 65+
  • Opera 12.10+
  • Safari 14+ (iOS 14+, macOS Big Sur+)

Animated WebP works in Chrome 32+, Edge 18+, Firefox 65+, Opera 19+, and Safari 14+. Safari was the last major browser to add support, in 2020. For live usage figures, check Can I use: WebP.

The remaining gap is mostly old in-app webviews, older operating systems, and email clients. A <picture> fallback covers them.

06How to Convert Images to WebP

There are four common ways to convert images to WebP. The right one depends on how many images you have and where they live.

1. Command line with cwebp

Google's cwebp tool is part of the libwebp download. To convert every JPEG in a folder on Linux or macOS:

· bash
for F in *.jpg; do cwebp "$F" -o "${F%.jpg}.webp"; done

Good for: one-off batches on your own machine. Limitation: someone has to run it, and it doesn't cover images uploaded later.

2. Build tools and image libraries

Image libraries such as sharp for Node.js convert during a build step:

javascript

· jsx
import sharp from "sharp";

await sharp("hero.png")
  .webp({ quality: 80 })
  .toFile("hero.webp");

Good for: static sites and apps with a build pipeline. Limitation: you install and maintain a native image library in every environment that runs it, including its security updates.

3. Image CDNs

Many CDNs convert and resize images on the fly and pick the format per browser. Good for: high-traffic sites already on a CDN. Limitation: it ties your image delivery to one provider's pricing and URL scheme.

4. A WebP conversion API

A conversion API takes an image (as an upload or a URL) and returns the WebP file. Good for: CMS uploads, user-generated content, e-commerce catalogs, and automation workflows where images arrive continuously. Limitation: each conversion is a network call, so batch or queue large backfills.

Convert your first image in the playground with no code and no card.

07Convert Images to WebP with the ApyHub API

The ApyHub catalog has three WebP converters, each with four endpoints: upload or URL input, and a binary file or signed link as output.

APIInputCost per call
Convert PNG to WebP APIPNG file or URL30 atoms
Convert JPEG to WebP APIJPEG/JPG file or URLSee service page
Convert SVG to WebP APISVG file or URL30 atoms

Multipart uploads accept up to 100 MB per request. The optional output query parameter sets the file name.

PNG to WebP: upload a file, download the result

· bash
curl -X POST "https://api.eu.apyhub.com/apyhub/convert-png-to-webp/multi-part/download?output=hero" \
  -H "apy-token: $APY_TOKEN" \
  -F "image=@./hero.png" \
  --output hero.webp

JPEG to WebP: convert from a URL, get a signed link

· bash
curl -X POST "https://api.eu.apyhub.com/apyhub/convert-jpeg-to-webp/url/link" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://assets.apyhub.com/samples/sample.jpg"}'

Response:

· json
{
  "data": "https://..."
}

SVG to WebP: rasterize vector artwork

SVG is already small for icons and logos, so keep SVG where you can. Convert to WebP when a platform only accepts raster images, such as social previews, marketplaces, or some email and CMS tools.

Try the SVG to WebP API

bash

· bash
curl -X POST "https://api.eu.apyhub.com/apyhub/convert-svg-to-webp/url/link" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://assets.apyhub.com/samples/sample.svg"}'

Python: convert a list of image URLs

python

· python
import os
import requests

API = "https://api.eu.apyhub.com/apyhub"
HEADERS = {"apy-token": os.environ["APY_TOKEN"]}

images = [
    "https://example.com/products/shoe.jpg",
    "https://example.com/banners/sale.png",
]

for url in images:
    kind = "png" if url.lower().endswith(".png") else "jpeg"
    r = requests.post(f"{API}/convert-{kind}-to-webp/url/link",
                      headers=HEADERS, json={"url": url}, timeout=60)
    r.raise_for_status()
    print(url, "->", r.json()["data"])

The same endpoints handle common errors consistently: 400 for a missing or malformed parameter, 401 for a missing or invalid key, 429 when you exceed your plan's per-second rate (retry with exponential backoff), and 503 when the backend is briefly unavailable.

Converting WebP back to PNG or JPEG

Some tools still don't accept WebP, such as older design software, print services, and a few upload forms. For those, use the Convert WebP to PNG API or the Convert WebP to JPEG API.

Convert WebP back to PNG · Convert WebP back to JPEG

Automating it

Try the PNG to WebP API →

08How to Serve WebP with a Fallback

Use the <picture> element

The browser uses the first <source> it supports and falls back to the <img>:

html

· js
<picture>
  <source srcset="/img/hero.avif" type="image/avif">
  <source srcset="/img/hero.webp" type="image/webp">
  <img src="/img/hero.jpg" alt="Product hero image"
       width="1600" height="900" fetchpriority="high">
</picture>

Setting width and height prevents layout shift, and fetchpriority="high" tells the browser to download the LCP image early.

Or negotiate on the server

Browsers that support WebP include image/webp in the Accept request header. Your server or CDN can check that header and return the WebP version from the same URL. If you do this, add Vary: Accept to the response so caches store the formats separately.

Don't lazy-load the LCP image

Use loading="lazy" for images below the fold, but not for the main hero image. The 2024 Web Almanac found that 15% of websites still lazy-load their LCP element, which delays the metric you're trying to improve.

09When WebP Files Get Bigger

Converting to WebP doesn't always shrink a file. Google's FAQ lists three cases where the WebP version can come out larger:

  1. A PNG with few colors converted to lossy WebP. Downsampling to YUV 4:2:0 introduces new colors that are harder to compress. Use lossless WebP for flat graphics and screenshots.
  2. A JPEG converted to lossless WebP. Lossless compression tries to preserve JPEG's compression artifacts, which costs bytes. Use lossy WebP for photos that are already JPEG.
  3. A low-quality JPEG converted at a higher WebP quality setting. Converting a quality-80 JPEG to quality-95 WebP usually produces a larger file. Lower the target quality, or target a file size instead.

Google notes that JPEG to lossy WebP and PNG to lossless WebP don't normally cause these surprises. Compare the output size with the original, and keep the original when the WebP isn't smaller.

Test both settings on your own image

10WebP Conversion Checklist

  1. Audit which images are largest and which ones are LCP elements on your key pages.
  2. Keep original PNG and JPEG files as your source of truth.
  3. Convert photos to lossy WebP and graphics or screenshots to lossless WebP.
  4. Compare output sizes and keep whichever file is smaller.
  5. Resize images to the dimensions they're displayed at before or during conversion.
  6. Serve WebP with a <picture> fallback or Accept-header negotiation.
  7. Add AVIF as the first <source> for large photos if your pipeline can handle the slower encoding.
  8. Set width and height, preload or prioritize the LCP image, and lazy-load only below-the-fold images.
  9. Automate conversion for new uploads so the library doesn't drift back to JPEG and PNG.
  10. Re-measure LCP in PageSpeed Insights after deploying.

11Conclusion

WebP is supported by every current major browser, compresses better than JPEG and PNG, and still accounts for only about one in ten LCP images on the web. Converting your library, serving it with a fallback, and automating conversion for new uploads is one of the most direct ways to reduce page weight in 2026. Add AVIF on top for large photos once the WebP pipeline is in place.

Explore the image conversion APIs in the ApyHub catalog →

12FAQ

What is WebP? WebP is an open image format from Google that supports lossy and lossless compression, transparency, and animation. It produces smaller files than JPEG and PNG at similar visual quality.

How much smaller are WebP files? Google reports that lossless WebP images are 26% smaller than PNGs and that lossy WebP averages about 30% more compression than JPEG. Animated GIFs converted to lossy WebP are 64% smaller.

Is WebP better than PNG? For web delivery, usually yes: lossless WebP keeps full quality and transparency at a smaller size. Keep PNG for source files and for tools that don't accept WebP.

Is WebP better than JPEG? For photos on websites, lossy WebP is typically smaller than JPEG at comparable quality and also supports transparency. JPEG remains the safest universal fallback.

Should I use AVIF or WebP in 2026? Use both where you can: AVIF first for large photos, WebP as the fallback, and JPEG or PNG last. If you add only one modern format, WebP has broader support and encodes faster.

Do all browsers support WebP? All current major browsers support WebP, including Chrome, Edge, Firefox, Opera, and Safari 14 and later. Use a <picture> element with a JPEG or PNG fallback for older clients.

How do I convert PNG to WebP? Use Google's cwebp command-line tool, an image library such as sharp, or a conversion API. ApyHub's Convert PNG to WebP API accepts an upload or a URL and returns the WebP file or a signed link.

Can I convert SVG to WebP? Yes. ApyHub's Convert SVG to WebP API rasterizes an SVG file or URL into WebP. Keep SVG for icons and logos on your own site, and convert when a platform only accepts raster images.

Can a WebP file be larger than the original? Yes, mainly when converting a few-color PNG to lossy WebP, a JPEG to lossless WebP, or a low-quality JPEG at a higher WebP quality. Compare sizes and keep the smaller file.

Does converting images to WebP improve SEO? Smaller images load faster, which can improve Largest Contentful Paint, one of Google's Core Web Vitals. Image format is one factor among several that affect page experience.

How do I convert WebP back to PNG or JPG? Use ApyHub's Convert WebP to PNG API or Convert WebP to JPEG API, or an image library such as sharp. This helps when a tool or upload form doesn't accept WebP.

13Related reading

14References