/ โ† Image Optimisation Fixes / Image Format
In this guide
  1. The four kinds of wrong format
  2. Choosing a format for each kind of image
  3. Converting images properly
  4. Two ways to serve modern formats
  5. Finding out what format is really delivered
  6. The fix, step by step
  7. Places where modern formats cause trouble
  8. Stopping old formats creeping back
  9. Questions and answers

The four kinds of wrong format

The Image Optimisation audit reports a format problem when the format in use is heavier than it needs to be for that kind of image. In practice almost every case falls into one of four groups, and each has a different fix.

  1. A photograph in a lossless format. PNG keeps every pixel exactly, which is ideal for a screenshot and wasteful for a photo of a sofa, where the camera noise alone makes the file huge. This often happens when a designer exports everything from the same tool with the same setting, or a PNG is needed for transparency on one image and becomes the habit for all of them.
  2. An animation in GIF. GIF is limited to 256 colours per frame and compresses poorly, so even a few seconds of animation can weigh several megabytes. A short muted video is usually a small fraction of that size.
  3. A drawing saved as pixels. Logos, icons and simple diagrams are made of shapes. Saved as JPEG they get blurry edges and coloured fringes; saved as PNG they are sharp but need a separate file for each size. SVG describes the shapes themselves, stays sharp at any size, and is often tiny.
  4. No modern alternative. The image is a sensible JPEG or PNG, but browsers that support AVIF or WebP are not offered them, so they download a larger file than necessary.

The first three are about choosing the right format for the content. The fourth is about delivery: keeping a widely readable fallback while giving capable browsers something smaller.

Choosing a format for each kind of image

Decide by what the image contains, not by habit. These questions settle most cases:

AVIF, WebP or both

AVIF often gives smaller files than WebP for photos at similar visual quality, but it is slower to encode and not every tool or platform produces it. WebP is quicker to encode and very widely supported by software. Offering both, AVIF first, is the most thorough approach; WebP alone is still a clear step up from JPEG and PNG, and a reasonable place to stop if your pipeline cannot produce AVIF.

๐Ÿ’ก JPEG XL is supported in some browsers and has been discussed for others, but it is not yet something to rely on as your only modern format. If you experiment with it, keep AVIF or WebP and a JPEG fallback in place.

Converting images properly

Always convert from the best source you have: the camera original, the design export or a high-quality master. Converting an already heavily compressed JPEG to WebP or AVIF bakes its blocky artefacts into the new file, and each lossy step adds more.

One-off images

Squoosh, a free browser-based tool, lets you compare the original and the converted image side by side with a quality slider, which is the best way to learn what setting each kind of image tolerates.

Batches from the command line

# WebP, lossy, for photographs
cwebp -q 80 sofa.jpg -o sofa.webp

# WebP, lossless, for a screenshot with text
cwebp -lossless dashboard.png -o dashboard.webp

# AVIF with libavif; quality flag names vary between versions,
# so check avifenc --help for yours
avifenc -q 60 sofa.jpg sofa.avif

# ImageMagick 7 can do either
magick sofa.jpg -quality 80 sofa.webp

# Clean up an SVG logo exported from a design tool
npx svgo logo.svg -o logo.min.svg

In a Node.js build or upload handler

import sharp from 'sharp';

const src = sharp('masters/sofa.jpg');
await src.clone().avif({ quality: 50 }).toFile('public/img/sofa.avif');
await src.clone().webp({ quality: 78 }).toFile('public/img/sofa.webp');
await src.clone().jpeg({ quality: 80, mozjpeg: true }).toFile('public/img/sofa.jpg');

Quality numbers are not comparable between formats or encoders. A quality of 50 in one AVIF encoder is not the same as 50 in WebP or JPEG. Pick settings by comparing images by eye on a few typical photos, then apply them to the rest. Compression settings in more depth are covered in the guide to oversized image files.

Two ways to serve modern formats

1. The picture element

The page lists each format and the browser takes the first one it supports. It works on any host, needs no server changes and is easy to inspect. The cost is longer markup and three files per image.

<picture>
  <source type="image/avif" srcset="/img/sofa.avif">
  <source type="image/webp" srcset="/img/sofa.webp">
  <img src="/img/sofa.jpg" width="1600" height="1067"
       alt="Green velvet two-seater sofa with walnut legs">
</picture>

The alt, width, height and loading attributes all go on the <img>, which is the element the browser actually displays whichever source it picks.

2. Content negotiation on the server or CDN

Browsers send an Accept header listing the image types they can decode. The server can read it and send AVIF or WebP from the same URL, keeping the markup as a plain <img>. Many image CDNs and platforms do this automatically. On your own Nginx server, with converted files stored beside the originals, it looks like this:

map $http_accept $img_suffix {
    default        "";
    "~image/avif"  ".avif";
    "~image/webp"  ".webp";
}

server {
    location ~* ^(/img/.+)\.(jpe?g|png)$ {
        add_header Vary Accept;
        try_files $1$img_suffix $uri =404;
    }
}

With this in place, a request for /img/sofa.jpg from a browser that accepts AVIF receives /img/sofa.avif, and other browsers get the JPEG. The Vary: Accept header tells caches that the response depends on that header.

โš ๏ธ Content negotiation and caching must agree. If a CDN in front of your server ignores Vary: Accept, it may cache the AVIF version and hand it to a browser that cannot show it, or cache the JPEG and hand it to everyone. Check your CDN's documentation for how it handles image negotiation, or let the CDN do the conversion itself.

Finding out what format is really delivered

File extensions are not reliable. A URL ending in .jpg may deliver WebP from a negotiating CDN, and a .webp file may have been renamed from a PNG without conversion. Check what arrives:

  1. Open developer tools, go to the Network panel, reload and filter by images. The Type column shows the format the browser received. Sort by size to see the heaviest first.
  2. Click a large image and check the Content-Type response header. It should say image/avif, image/webp, image/jpeg, image/png, image/svg+xml or image/gif.
  3. Test negotiation from the command line by sending different Accept headers:
# What a modern browser receives
curl -sI -H "Accept: image/avif,image/webp,*/*" https://www.example.co.uk/img/sofa.jpg | grep -iE "^content-type|^vary"

# What an older client receives
curl -sI -H "Accept: */*" https://www.example.co.uk/img/sofa.jpg | grep -iE "^content-type|^vary"

If both requests return image/jpeg, nothing is negotiating. If the first returns AVIF or WebP but there is no Vary header, caching may go wrong. Record the results for your heaviest images before you change anything, so you can measure the saving afterwards.

The fix, step by step

Step 1

List images by the format actually delivered

Run the Image Optimisation audit on your key templates, then open the Network panel in developer tools, filter by images and sort by size. Record each heavy image's delivered format from the Content-Type header, not from the file extension, and note whether it is a photograph, screenshot, logo, icon or animation. This list shows which of the four kinds of format problem you have and where to start.

Step 2

Match each image to the right kind of format

Photographs should be AVIF or WebP with a JPEG fallback. Logos, icons and line drawings should be optimised SVG. Screenshots and charts with small text should be lossless WebP or a well-optimised PNG. Transparent product cut-outs can move from PNG to WebP or AVIF with transparency. Animations should become video. Write the target format beside each image in your list before converting anything.

Step 3

Convert from the best original you have

Go back to the camera original, the design export or a high-quality master rather than the compressed file on the site. Use Squoosh to choose quality settings by eye on a few typical images, then convert the rest in bulk with sharp, cwebp, avifenc or ImageMagick. Run SVG logos through SVGO. Keep the originals safely stored so you can re-encode later without losing quality.

Step 4

Serve modern formats with a fallback

Either wrap images in a <picture> element with AVIF and WebP sources before a JPEG or PNG <img>, or let your server or CDN choose the format from the browser's Accept header. Use the picture element when you cannot change server settings. Use negotiation when you control the server or your platform already offers it, which keeps templates simple and needs no markup changes.

Step 5

Send the right Content-Type and Vary headers

Check that each converted file is sent with a matching Content-Type, such as image/avif or image/webp, since some older servers lack AVIF in their MIME type list and send a generic type instead. If the server negotiates formats, add Vary: Accept and confirm that your CDN respects it, so a cached AVIF is never handed to a browser that cannot decode it.

Step 6

Replace animated GIFs with video

Convert each animated GIF to MP4, and optionally WebM, with a tool such as ffmpeg. Show it with a <video> element using autoplay, muted, loop and playsinline so it behaves like the GIF did, and set width and height. Provide a pause control for longer animations, because motion that cannot be stopped is an accessibility problem as well as a weight problem.

Step 7

Check the result in browsers and on share cards

Reload in Chrome, Firefox and Safari and confirm in the Network panel that each receives a modern format where supported and the fallback otherwise. Repeat the curl tests with different Accept headers. Check images used outside the page, such as Open Graph share images, email images and product feeds, where a plain JPEG or PNG may still be required, and re-run the audit to confirm the saving.

Places where modern formats cause trouble

Stopping old formats creeping back

For choosing and configuring a CDN that converts formats for you, see fixing image CDN delivery.

Questions and answers

1. Should I convert all my images to WebP or AVIF?

Convert photographs and complex images, yes, but keep a JPEG or PNG fallback for anything that is not a browser: social share crawlers, email clients, feeds and people saving the file. Logos and icons are usually better as SVG than either format, and screenshots with fine text may need lossless WebP or PNG to stay crisp. The aim is the right format for each image and each destination, not one format everywhere.

2. Is AVIF better than WebP?

For photographs AVIF often produces a smaller file than WebP at a similar visual quality, which is why it is usually offered first. It is slower to encode, and some tools, hosts and platforms still cannot produce it. WebP encodes quickly and is supported by nearly every image tool. If you can offer both, list AVIF first and WebP second with a JPEG fallback. If you can only manage one, WebP is still a large improvement over JPEG.

3. Why does my .jpg image show as WebP in developer tools?

Because a server or CDN is choosing the format from the browser's Accept header and sending WebP from the same address. This is content negotiation, and many image CDNs and platforms do it automatically. The file extension in the URL no longer tells you the delivered format, so always check the Content-Type response header. Make sure the response also includes a Vary header naming Accept, so caches keep the different versions apart.

4. Will converting a JPEG to WebP make it look worse?

It can if you convert from a file that is already heavily compressed, because the new encoder preserves the old artefacts and adds its own. Convert from the original camera file or a high-quality master wherever possible, and choose the quality setting by comparing side by side in a tool such as Squoosh. Done that way, most photographs look the same to visitors while the file becomes noticeably smaller than the original JPEG.

5. Where do alt, width and loading go in a picture element?

On the img element inside the picture. The source elements only offer alternative files; the img is what the browser actually displays, whichever source it chose, so its alt text, width, height, loading and fetchpriority attributes apply to every format. The img src should point to the fallback format, usually JPEG or PNG, for browsers that support none of the sources. Adding alt to source elements does nothing, so any text written there is simply ignored.

6. How do I replace an animated GIF on my website?

Convert it to an MP4 video, and optionally WebM, with a tool such as ffmpeg, then show it with a video element set to autoplay, muted, loop and playsinline so it starts by itself and repeats like the GIF did. Set width and height to reserve space. The video is usually far smaller than the GIF and has smoother colour. For anything longer than a few seconds, add a way to pause the motion.

7. Can my server choose the image format automatically?

Yes. The browser sends an Accept header listing the image types it supports, and a server or CDN can use it to send AVIF, WebP or JPEG from the same address. On Nginx this can be done with a map on the Accept header and try_files pointing at converted copies stored beside the originals. Always send a Vary header naming Accept, and check your CDN handles it, or the wrong format can be cached.

Check the formats on your pages

The Image Optimisation audit checks every image on your page for format as well as file size, dimensions, alt text, lazy-loading, layout shift and CDN delivery, and ranks its recommendations by their effect on loading and bandwidth.

Open Image Optimisation Fixes โ†’
๐Ÿ’ฌ Got a problem?
Related Guides: All Image Optimisation Fixes  ·  Oversized Image Files  ·  Image CDN Delivery  ·  Image Optimisation Guide  ·  Learning Hub

About aiwebpageseo

aiwebpageseo.com is a data-driven SEO and AEO (Answer Engine Optimisation) platform providing a free suite of technical SEO tools. Rather than relying on AI-theorised assumptions, the platform analyses live URL performance, delivering objective diagnostics, page speed metrics, CLS debugging, and site crawl data alongside actionable technical tutorials.