---
title: "Image Optimization for the Web: AVIF, WebP, srcset and Lazy Loading"
description: "Making website images fast: choosing a format (AVIF, WebP, JPEG), sizing, srcset and sizes, lazy loading, prioritising the LCP image and preventing layout shift."
url: https://sanderyaz.com/en/blog/web-image-optimization/
author: Sander Yazıcıoğlu
date: 2026-12-02
updated: 2026-12-02
lang: en
tags: ["Performance","SEO","Frontend","Core Web Vitals"]
---

# Image Optimization for the Web: AVIF, WebP, srcset and Lazy Loading

On the sites I built for health-tourism, logistics and corporate clients, the biggest performance win almost always came from the same place: **images**. Images are usually more than half of a page's weight, and the Largest Contentful Paint (LCP) element is very often a hero image.

## 1. The right format

| Format | When |
|---|---|
| AVIF | Best compression for photos; supported by all modern browsers |
| WebP | Wide support, clearly smaller than JPEG |
| JPEG | Fallback for old browsers |
| PNG | Simple graphics needing transparency (WebP is often better) |
| SVG | Logos, icons, diagrams |

Use `<picture>` to let the browser pick the best format it supports:

```html
<picture>
  <source srcset="/img/clinic.avif" type="image/avif" />
  <source srcset="/img/clinic.webp" type="image/webp" />
  <img src="/img/clinic.jpg" alt="Waiting room of the clinic in Antalya" width="1200" height="800" />
</picture>
```

## 2. The right size

Showing a 3000-pixel photo in a 400-pixel card is the most common waste. Give the browser options with `srcset` and `sizes`:

```html
<img
  src="/img/card-800.webp"
  srcset="/img/card-400.webp 400w, /img/card-800.webp 800w, /img/card-1200.webp 1200w"
  sizes="(max-width: 760px) 100vw, 380px"
  alt="Team meeting"
  width="800" height="450"
  loading="lazy" decoding="async" />
```

`sizes` tells the browser how wide the image will render; the browser factors in screen density and downloads the best-fitting file.

## 3. Lazy loading, but not for the LCP image

`loading="lazy"` keeps off-screen images from downloading until the user gets close. The main image on the first screen needs the opposite:

```html
<img src="/img/hero.avif" alt="..." width="1600" height="900" fetchpriority="high" />
```

Lazy-loading the LCP image is the mistake I see most often, and it delays LCP by seconds. On this blog, article covers load with `fetchpriority="high"` while thumbnails in lists use `loading="lazy"`.

## 4. Prevent CLS: declare dimensions

Give every image a `width` and `height`. The browser reserves space using that ratio, so text doesn't jump when the image arrives. `width: 100%; height: auto;` in CSS keeps it responsive. I cover the other Core Web Vitals techniques in the [Core Web Vitals article](/en/blog/react-core-web-vitals-lcp/).

## 5. Compression quality

You don't need quality 100. For photos, roughly 50–60 for AVIF and 75–80 for WebP is usually indistinguishable to the eye and halves the file. Use `sharp`, `squoosh` or your build tool's image plugins for batch conversion, and wire it into the build; manual optimisation gets forgotten.

## 6. Caching and CDNs

Put a content hash in the file name (`hero.3f9a1c.avif`) and serve it with a long `immutable` cache. A CDN serves images close to users, and some can convert format and size on the fly.

## 7. Images for SEO

- **Meaningful `alt` text:** describe what the image shows; don't stuff keywords. Use `alt=""` for decorative images.
- **Meaningful file names:** `antalya-dental-clinic.jpg` instead of `IMG_4821.jpg`.
- **Image sitemaps** and an Open Graph image: for visibility in shares and Google Images.

## Quick checklist

- Hero image in AVIF/WebP, correctly sized, `fetchpriority="high"`
- Other images `loading="lazy"`
- `width`/`height` on every `<img>`
- Responsive sizes with `srcset` + `sizes`
- Long-lived caching and a CDN
- Meaningful `alt` text

## Conclusion

Image optimisation gives the biggest speed win for the least effort on most websites. The right format, the right size, the right loading priority and fixed dimensions: these four rules noticeably cut LCP and page weight on most sites.

---

About the author: [Sander Yazıcıoğlu](https://sanderyaz.com/en/about/). Sander Yazıcıoğlu is a Senior Full-Stack Developer in Istanbul. At LiveTesting he builds the backend, frontend, realtime systems and Appium automation of a real-device testing platform; before that he built enterprise Angular apps at Testinium and Loadium.
