On this page
This is a reference guide that works for any platform (a custom site, WordPress or a store), because the principles of image optimization are the same even if the tools differ. We will explain each step in depth with comparison tables and practical code, then close with a ready-made workflow, a checklist, common mistakes and frequently asked questions. For the bigger picture, also read the complete guide to speeding up your website, which puts images in the context of overall performance.
Why are images the heaviest element on the page?
On most sites, if you open the developer tools and sort network requests by size, you will find images at the top of the list, far ahead of HTML, CSS and even JavaScript. The reason is simple: a photo carries millions of pixels, and every pixel is a color. An unoptimized 2000×1333-pixel JPEG can easily exceed 2 megabytes, while a complete HTML page rarely goes beyond a few dozen kilobytes.
The impact of this weight does not stop at "the page is heavy." It is reflected directly in two of the Core Web Vitals:
- LCP (Largest Contentful Paint): on most pages, the largest visible element is an image: the hero image, the article cover or the main product image. Unless this image loads quickly, LCP will remain poor however much you optimize the rest of the page. The official target is under 2.5 seconds.
- CLS (Cumulative Layout Shift): an image without reserved dimensions suddenly pushes the content down when it arrives, so the layout jumps and CLS rises. The target is under 0.1.
Worse still, slowness has a direct business cost: the longer loading takes, the more likely the visitor is to leave before even engaging. This relationship between load time and bounce rate is well documented.
The good news is that images are also the biggest opportunity for improvement: saving 70% of an image's weight is far easier than saving 70% of your JavaScript, and it usually doesn't require touching the code. That makes optimizing images the first thing to start with in any speed project. To understand the metrics in detail, see understanding Core Web Vitals.
The image pipeline: from upload to browser
Before diving into the details, it helps to see the image's whole journey, from the moment the photographer or designer captures it until it appears in the visitor's browser. Every step in this pipeline is an opportunity to optimize, or to neglect.
The steps in order:
- Source: a high-resolution original file (PNG/JPEG/PSD), possibly several megabytes.
- Resize: reduce the dimensions to what the page actually needs, no more.
- Encode (choose the format): convert to AVIF/WebP with JPEG as a fallback.
- Compress: set the quality level to balance size and clarity.
- Generate multiple sizes: copies at different widths for
srcset. - Storage and delivery (CDN): upload to object storage and deliver from the nearest point.
- Display in the browser: with
width/height,loading,decodingandsizes.
Any site that does not apply this pipeline pays twice: once in weight and once in experience. Let's go through each step in detail.
Step 1: choosing the right format
There is no absolute "best format"; each format has its ideal use. The general rule: AVIF, then WebP, for photos and complex graphics, SVG for icons and logos, and JPEG/PNG as a fallback only when needed.
Comparing the five main formats
| Format | Best use | Support | Relative size | Transparency | Animation |
|---|---|---|---|---|---|
| JPEG | Photos (fallback) | Universal (100%) | Baseline (100%) | No | No |
| PNG | Transparency, sharp text, screenshots | Universal (100%) | Very large for photos | Yes | No |
| WebP | A general replacement for JPEG/PNG | Excellent (~97%) | ~25–35% smaller than JPEG | Yes | Yes |
| AVIF | The best compression for modern images | Good (~93%) | ~50% smaller than JPEG | Yes | Yes |
| SVG | Icons, logos, vector graphics | Universal (100%) | Very small | Yes | Yes (CSS/SMIL) |
When should you choose each format?
| Scenario | Ideal format | Fallback |
|---|---|---|
| A photographic hero image | AVIF | WebP → JPEG |
| An article cover / blog image | AVIF | WebP → JPEG |
| A product image (fine details) | AVIF at higher quality | WebP → JPEG |
| A logo, icon or vector chart | SVG | PNG |
| A screenshot with sharp text | WebP (lossless) | PNG |
| A graphic that needs sharp transparency | WebP/AVIF | PNG |
| An old animated GIF | WebP or MP4/WebM video | — |
Two important tips: first, animated GIFs are very bad for weight; replace them with a <video> in WebM/MP4 format or with animated AVIF/WebP, and the savings reach 90%. Second, don't use PNG for a photo; PNG is designed for lossless compression, so it produces a huge file for images with many color gradients. PNG is excellent for sharp text and transparency only.
As for the delivery mechanism, the simplest reliable way is the <picture> element, which serves AVIF first, then WebP, then JPEG for browsers that don't support the modern formats:
<picture>
<source srcset="/images/hero.avif" type="image/avif" />
<source srcset="/images/hero.webp" type="image/webp" />
<img src="/images/hero.jpg" alt="Hosting control panel" width="1200" height="630" />
</picture>The browser picks the first format it supports, from top to bottom, so users of modern browsers get the lighter AVIF, and everyone can still see the image. If you are on WordPress or a CDN that converts formats automatically, you probably won't write this by hand, but understanding the mechanism helps you diagnose problems.
Step 2: compression, lossy vs. lossless
There are fundamentally two kinds of compression, and mixing them up is one of the most common mistakes:
| Type | The idea | Quality | Size | Ideal use |
|---|---|---|---|---|
| Lossless | Removes redundancy without deleting any pixel | 100% identical to the original | Moderate reduction | Screenshots, sharp text, logos |
| Lossy | Deletes details the eye can hardly tell apart | Slight visual loss, controlled by the quality level | Very large reduction | Photos |
For photos, lossy compression is almost always the right choice: the human eye cannot see the difference between the original and a copy compressed at quality 80, while the size drops to a third or less. The real question is: what quality level is right?
Quality vs. size: where do you set the dial?
| Quality level | Visual perception | Relative size | Recommendation |
|---|---|---|---|
| 95–100 | No noticeable difference; wasteful | Large | Avoid it; waste with no benefit |
| 82–90 | Excellent; safe for detailed products | Medium to large | For product images and anything that gets zoomed |
| 75–82 | Excellent to the eye; the ideal balance | Medium | The recommended default |
| 60–74 | Good; some loss visible on close inspection | Small | For secondary images and thumbnails |
| < 55 | Obvious artifacts | Very small | Avoid it for important images |
The golden rule: start at quality 80 and go down gradually until you see the first visual difference, then go up one step. This is the "visual quality threshold," and it varies slightly from image to image: images with flat areas of color (sky, a wall) tolerate more compression than images crowded with detail (leaves, textures).
Command-line tools give you precise control. To convert an image to WebP at quality 80 with the cwebp tool:
# Lossy WebP at quality 80
cwebp -q 80 input.jpg -o output.webp
# Lossless WebP (for screenshots and sharp text)
cwebp -lossless input.png -o output.webpAnd to generate AVIF with avifenc (from the libavif package):
# Lossy AVIF: lower --min/--max = higher quality; speed 6 is a good balance
avifenc --min 24 --max 30 --speed 6 input.jpg output.avifStep 3: resizing and responsive images (srcset)
The single biggest image mistake is uploading an image with huge dimensions and displaying it small. A 4000-pixel-wide image displayed in a 400-pixel-wide container wastes 90% of its data, and the browser is forced to download it in full and then scale it down. The solution has two parts: resize to what you need, and serve multiple sizes for different screens.
Common display dimensions
| Image position | Approximate display width | Suggested srcset widths |
|---|---|---|
| A wide hero image (full-width) | Up to 1920px | 640, 960, 1280, 1920 |
| An article cover | Up to 1200px | 480, 768, 1024, 1200 |
| An in-body image | Up to 760px | 380, 560, 760 |
| A card in a grid | ~360px | 360, 540, 720 |
| Thumbnail | ~120px | 120, 240 |
| Avatar | ~48px | 48, 96 |
Notice that each row includes a copy at double the width (such as 360 and 720): this covers high-density screens (DPR ≥ 2, such as Retina displays), which need more physical pixels for each CSS pixel.
How do srcset and sizes work together?
The srcset attribute tells the browser which copies are available and the width of each in pixels (with the w descriptor), and the sizes attribute tells it the width at which the image will actually be displayed at each breakpoint, so the browser picks the most suitable copy on its own based on the screen and its density:
<img
src="/images/cover-768.jpg"
srcset="
/images/cover-480.jpg 480w,
/images/cover-768.jpg 768w,
/images/cover-1024.jpg 1024w,
/images/cover-1200.jpg 1200w"
sizes="(max-width: 600px) 100vw, (max-width: 1024px) 80vw, 1200px"
width="1200" height="630"
alt="Comparison of hosting plans"
decoding="async"
/>Read sizes like this: "On screens up to 600 pixels, display the image at the full viewport width (100vw); up to 1024 pixels, at 80% of the width; otherwise at 1200 pixels." With this information, the browser can calculate the smallest sufficient copy for each device. Without accurate sizes, you lose the benefit of srcset, because the browser assumes the image is full-screen width and picks a larger copy than needed.
A key point: don't write all of this by hand for every image. On WordPress, the system generates
srcset/sizesautomatically from the registered "image sizes," and in Next.js,next/imagehandles the generation entirely. Your job is to make sure the multiple copies are generated and thatsizesreflects your real layout.
Step 4: lazy loading without hurting LCP
Lazy loading defers downloading images outside the screen's viewport until the user scrolls close to them, which speeds up the initial load and saves data on images the visitor may never reach. Enabling it has become simple with a native browser attribute:
<!-- An image lower down the page: lazy-load it -->
<img src="/images/section-3.webp" loading="lazy" decoding="async"
width="800" height="450" alt="Statistics dashboard" />But here is the most dangerous trap in the whole topic:
Never lazy-load the LCP image, that is, the first visible image above the fold, such as the hero image or the article cover. Lazy-loading it delays its download, so LCP gets much worse, which is the opposite of what you want.
The practical rule:
| Image position | loading | fetchpriority | Reason |
|---|---|---|---|
| The LCP image (hero/cover, above the fold) | eager (the default) | high | Load it immediately and with high priority |
| Above-the-fold images other than LCP | eager | — | Visible immediately |
| All images below the fold | lazy | — | Defer them until the user gets close |
To speed up the LCP image specifically, add fetchpriority="high" to raise its priority in the download queue:
<!-- The hero / LCP image: load it early -->
<img src="/images/hero.avif" fetchpriority="high" decoding="async"
width="1200" height="630" alt="Fast hosting" />The decoding="async" attribute lets the browser decode the image without blocking the main thread; it is safe for most images and helps responsiveness.
An expert tip: on WordPress, the core adds loading="lazy" to all images automatically, sometimes including the LCP image. Make sure your theme or performance plugin excludes the first image (or gives it fetchpriority="high"). Many slow sites are slow because the hero image is lazy-loaded by mistake.
Step 5: setting width and height to avoid CLS
When the browser does not know an image's dimensions in advance, it reserves zero space for it and then suddenly pushes everything below it down when it arrives; this is the best-known cause of layout shift (CLS). The fix is very simple and often neglected: write the real width and height (in pixels) on every image, even if it is responsive.
<!-- Aspect ratio preserved: the browser reserves the space before the download -->
<img src="/images/chart.webp" width="800" height="450"
style="height:auto" alt="Performance growth" loading="lazy" />The secret is that modern browsers use width and height to calculate the aspect ratio, so they reserve a box of the right size before the image arrives. With style="height:auto" (or an equivalent CSS rule), the image stays responsive but its ratio is preserved, so nothing jumps. This is the cheapest optimization step of all: one line per image drops CLS to almost zero.
| Case | Effect on CLS |
|---|---|
An image without width/height | A severe jump when it arrives: high CLS |
width/height + height:auto | Space reserved: CLS ≈ 0 |
A container with a CSS aspect ratio (aspect-ratio) | An excellent alternative that also reserves the space |
Step 6: delivery through a CDN and automatic format conversion
After compressing and resizing your images, one factor remains: distance. A visitor geographically far from your server waits longer for the image to arrive. This is where a content delivery network (CDN) comes in: it stores copies of your images at points of presence distributed around the world and serves each visitor from the nearest point. This noticeably cuts the image's arrival time (and therefore LCP) for an international audience.
Better still, modern image CDNs do more than delivery: they convert the format, resize and compress on demand based on the visitor's browser and screen size. You upload a single original image and request it with a URL carrying parameters, and the network returns the optimal copy:
# Example: an image CDN URL that resizes, converts and sets quality on demand
https://cdn.example.com/hero.jpg?width=768&format=auto&quality=80format=auto means: "Give this visitor AVIF if their browser supports it, otherwise WebP, otherwise JPEG," automatically, without you generating the copies yourself. This simplifies the workflow a lot. For a deeper understanding of how a CDN works and its security and performance benefits, see what a CDN is and why you need one.
If you serve WebP manually from your server without a CDN, you can configure Nginx to serve a WebP copy automatically to supporting browsers based on the Accept header:
# Serves x.webp instead of x.jpg if the browser supports webp and the copy exists
location ~* \.(jpe?g|png)$ {
add_header Vary Accept;
try_files $uri$webp_suffix $uri =404;
}
map $http_accept $webp_suffix {
default "";
"~*image/webp" ".webp";
}Tools: from manual to online to plugins
You don't need every tool; you need the right tool for your context. Here is a practical map:
Compression and conversion tools
| Tool | Type | Features | Best for |
|---|---|---|---|
| Squoosh | Online (free) | Live before/after comparison, AVIF/WebP, fine control | Individual images, learning the thresholds |
| TinyPNG | Online (free/paid) | Smart PNG/JPEG/WebP compression, API | Quick batches |
| cwebp / avifenc | Command line | Full control, automation, huge batches | Developers and CI |
| ShortPixel | Plugin/online/API | Automatic AVIF/WebP conversion, optional CDN | WordPress and live sites |
| Imagify | Plugin/online/API | Automatic compression at different levels, WebP/AVIF | WordPress |
| Sharp | A Node.js library | The fastest programmatic processing, srcset generation | Builds and pipelines |
WordPress image plugins
| Plugin | Core function | Note |
|---|---|---|
| ShortPixel | Compression + WebP/AVIF conversion + CDN | Comprehensive and easy |
| Imagify | Compression at different levels + WebP/AVIF | From the makers of WP Rocket |
| EWWW Image Optimizer | Local/cloud compression + WebP | Works without a subscription for the basics |
| Smush | Compression + lazy loading + resizing | A simple interface |
| Converter for Media | Converting and serving WebP/AVIF | Specialized in conversion |
A tip: don't combine more than one compression plugin; they may conflict and compress the image twice, ruining it. Choose one and configure it well. And for more on speeding up WordPress as a whole, see speeding up a WordPress site.
A ready-made practical workflow
For a custom site (manual or build)
- Start from the highest-resolution original you will need (for example, 1920px for the hero).
- Resize to each width in your
srcsetplan (for example, 640/960/1280/1920). - Convert each width to AVIF and WebP (and keep JPEG as a fallback).
- Compress at quality 80 (lower for secondary images, higher for products).
- Display through
<picture>orsrcset/sizeswithwidth/height. - Lazy-load what is below the fold, and prioritize the LCP image with
fetchpriority="high". - Deliver through an image CDN with
format=auto.
A simple Node script using the Sharp library generates all the copies in one go:
import sharp from "sharp";
const widths = [640, 960, 1280, 1920];
for (const w of widths) {
await sharp("hero.jpg").resize(w)
.avif({ quality: 50 }).toFile(`hero-${w}.avif`);
await sharp("hero.jpg").resize(w)
.webp({ quality: 80 }).toFile(`hero-${w}.webp`);
}For a WordPress site
- Install one compression/conversion plugin (ShortPixel or Imagify) and enable WebP/AVIF.
- Enable "resize large images on upload" (WordPress does this by default above 2560px, and you can lower it).
- Compress the existing media library in one go (Bulk).
- Make sure the theme outputs
width/heightandsrcset(modern themes do). - Exclude the hero/cover image from lazy loading, and give it high priority.
- Enable a CDN (through the plugin or your provider).
Measuring: how do you know you have succeeded?
Optimization without measurement is guesswork. Use these tools:
| Tool | Measures | When to use it |
|---|---|---|
| PageSpeed Insights | Field + lab LCP/CLS + image recommendations | A full check and "next-gen formats" recommendations |
| Lighthouse (DevTools) | A detailed local audit of images | During development and diagnosis |
| DevTools > Network | The actual size and timing of each image | Finding the heaviest images quickly |
| WebPageTest | A precise loading waterfall + priorities | Advanced LCP diagnosis |
The fastest manual check: open DevTools > the Network tab > sort by Size descending > reload the page. The heaviest rows are your first targets. And in Lighthouse, watch for two recurring recommendations: "Serve images in next-gen formats" (that is, convert to WebP/AVIF) and **"Properly size images"** (that is, you are serving larger dimensions than are displayed).
Common mistakes and how to avoid them
| Mistake | Impact | Correction |
|---|---|---|
| Uploading images with huge dimensions and displaying them small | Enormous wasted weight and a slow LCP | Resize to the displayed dimensions + srcset |
| Using PNG for photos | Files 5–10 times larger | Use JPEG/WebP/AVIF |
| Lazy-loading the LCP image (hero/cover) | A sharp drop in LCP | eager + fetchpriority="high" for the first image |
Missing width/height | Layout jumps and a high CLS | Add both + height:auto |
| Quality 95–100 for no reason | Double the size with no visual benefit | Set it to 75–82 |
| A heavy animated GIF | Tens of megabytes | Replace it with <video> or WebP/AVIF |
Neglecting alt text | Harms accessibility and image SEO | Write descriptive alt text for every content image |
| Double compression by more than one plugin | Distorted, corrupted images | Only one compression plugin |
| Forgetting a CDN for an international audience | A slow LCP for distant visitors | An image CDN with format=auto |
The accessibility point deserves emphasis: alt text is not a luxury. It is what a screen reader reads aloud to a blind user, what the search engine relies on to understand the image, and what appears if the image fails to load. Write it descriptively and accurately for content images, and leave it empty (alt="") only for purely decorative images, so screen readers skip them.
A quick image optimization checklist
| Item | Done? |
|---|---|
| All photos are in AVIF/WebP with a fallback | ☐ |
| Icons and logos are in SVG | ☐ |
| No image is larger than its actual display dimensions | ☐ |
srcset + sizes for every responsive image | ☐ |
| Quality set to 75–82 (not 95+) | ☐ |
width + height + height:auto on every image | ☐ |
Below-the-fold images use loading="lazy" | ☐ |
The LCP image is not lazy-loaded + fetchpriority="high" | ☐ |
decoding="async" on images | ☐ |
Delivery through an image CDN with format=auto | ☐ |
Descriptive alt text for every content image | ☐ |
| Before/after measurement with PageSpeed/Lighthouse | ☐ |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Slow LCP despite compressed images | The LCP image is lazy-loaded or low priority | Remove lazy and add fetchpriority="high" |
| High CLS when images load | Missing width/height | Add the dimensions + height:auto |
| WebP/AVIF doesn't show for some visitors | No fallback, or a missing Vary header | Use <picture> or add Vary: Accept |
| Images look distorted (artifacts) | Compression quality is too low | Raise the quality above 70 |
| Images are still heavy after installing the plugin | The original dimensions are huge | Enable resizing on upload |
srcset saves nothing | sizes is inaccurate or missing | Set sizes to match the actual layout |
| An image is not served from the CDN | The cache hasn't warmed up, or the URL is the origin | Check the cf-cache-status/x-cache header |
| WordPress serves the large original copy | The theme doesn't support srcset, or the sizes were deleted | Regenerate the sizes (Regenerate Thumbnails) |
Frequently asked questions
What is the difference between WebP and AVIF, and which should I choose?
Both are modern formats with excellent compression and support for transparency and animation. AVIF produces smaller files (up to 50% smaller than JPEG), but its support is slightly narrower and its encoding is slower. WebP has wider support (~97% of browsers), encodes faster and is 25–35% lighter than JPEG. The best approach: serve AVIF first, then WebP, then JPEG through <picture> or a CDN with format=auto, so every visitor gets the best option available to them.
Can I drop JPEG and PNG entirely? Not yet. Keep JPEG as a fallback for the small share of old browsers, and keep PNG for screenshots, sharp text and critical transparency where lossless compression is required. But don't use them as the default format for photos; AVIF/WebP are lighter.
What is the ideal quality level for compression? For photos, 75 to 82 is an ideal balance between clarity and size that hardly anyone can tell apart by eye. Raise it to 85–90 for product images that get zoomed in, and lower it to 60–70 for secondary images and thumbnails. Avoid 95+, which is wasteful, and avoid anything below 55, which shows artifacts.
What is lazy loading, and when should I not use it?
Lazy loading (loading="lazy") defers downloading off-screen images until the user scrolls close to them, which speeds up the initial load. Never use it for the LCP image (the hero/cover above the fold); lazy-loading it delays the appearance of the largest element, so LCP gets worse. Lazy-load only what is below the fold.
How do images raise CLS, and how do I prevent it?
When an image arrives without reserved dimensions, it suddenly pushes the content below it, so the layout jumps (CLS). Prevent this by writing the real width and height on every image along with style="height:auto"; the browser then reserves the right space based on the aspect ratio before the image arrives. Another option: set an aspect-ratio for the container in CSS.
What is the right image size for the web? There is no single number; it depends on where the image is displayed: an optimized article cover is usually 50–150 KB, an in-body image smaller, and an optimized hero image may reach 150–250 KB. The rule: resize to the display dimensions, convert to AVIF/WebP, and set the quality to 80, and you will reach these numbers automatically. Any content image over half a megabyte is usually not optimized.
Does next/image optimize images automatically?
Yes. The next/image component generates srcset/sizes, converts to AVIF/WebP, adds width/height to prevent CLS, and lazy-loads what is below the fold automatically. Your job is to pass the correct dimensions and to set priority on the LCP image to load it early (equivalent to fetchpriority="high" and disabling lazy loading).
What should I do with animated GIFs?
Replace them. GIF is an old, very heavy format (sometimes tens of megabytes). Convert them to a <video> in WebM/MP4 format (with autoplay muted loop playsinline) or to animated AVIF/WebP; the savings reach 90% of the weight, with better quality.
Is using a CDN enough without compressing images? No. A CDN brings the image geographically closer, but it does not fix a 3 MB image; it stays heavy, just closer. The right order: compress and resize first, then deliver through a CDN. Best of all is an image CDN that converts and resizes on demand, combining both. See What is a CDN for details.
How do I actually measure the improvement from optimizing images? Run PageSpeed Insights and watch LCP and the "next-gen formats" and "properly size images" recommendations, or open DevTools > Network and sort by size to see the heaviest images before and after. Compare LCP and CLS before and after optimizing; the improvement should be noticeable in both numbers.
Does optimizing images help SEO?
Yes, in two ways: directly, by improving Core Web Vitals (a ranking signal in page experience), and indirectly, through descriptive alt text and meaningful file names that help the search engine understand the image and index it in image search. A faster site is also crawled more deeply and keeps visitors longer.
Conclusion
Images are the heaviest element on most pages, and therefore the biggest opportunity to speed them up. The recipe is clear and layered: a modern format (AVIF, then WebP), resizing to the actual dimensions, compression at quality 80, multiple sizes through srcset/sizes, lazy loading for what is below the fold while not lazy-loading the LCP image, reserved dimensions with width/height to prevent CLS, and delivery through a CDN with automatic conversion. Apply these steps and you will see page weight drop by 50–80% and Core Web Vitals improve right away.
Most importantly, server performance complements all this effort; light images on a slow server still fall short. Start optimizing your images today, make sure your hosting is not the bottleneck, and measure the result.
Sources
Frequently asked questions
What is the difference between WebP and AVIF, and which should I choose?
Both are modern formats with excellent compression and support for transparency and animation. AVIF produces smaller files (up to 50% smaller than JPEG), but its support is slightly narrower and its encoding is slower. WebP has wider support (~97% of browsers), encodes faster and is 25–35% lighter than JPEG. The best approach: serve AVIF first, then WebP, then JPEG through <picture> or a CDN with format=auto, so every visitor gets the best option available to them.
Can I drop JPEG and PNG entirely?
Not yet. Keep JPEG as a fallback for the small share of old browsers, and keep PNG for screenshots, sharp text and critical transparency where lossless compression is required. But don't use them as the default format for photos; AVIF/WebP are lighter.
What is the ideal quality level for compression?
For photos, 75 to 82 is an ideal balance between clarity and size that hardly anyone can tell apart by eye. Raise it to 85–90 for product images that get zoomed in, and lower it to 60–70 for secondary images and thumbnails. Avoid 95+, which is wasteful, and avoid anything below 55, which shows artifacts.
What is lazy loading, and when should I not use it?
Lazy loading (loading="lazy") defers downloading off-screen images until the user scrolls close to them, which speeds up the initial load. Never use it for the LCP image (the hero/cover above the fold); lazy-loading it delays the appearance of the largest element, so LCP gets worse. Lazy-load only what is below the fold.
How do images raise CLS, and how do I prevent it?
When an image arrives without reserved dimensions, it suddenly pushes the content below it, so the layout jumps (CLS). Prevent this by writing the real width and height on every image along with style="height:auto"; the browser then reserves the right space based on the aspect ratio before the image arrives. Another option: set an aspect-ratio for the container in CSS.
What is the right image size for the web?
There is no single number; it depends on where the image is displayed: an optimized article cover is usually 50–150 KB, an in-body image smaller, and an optimized hero image may reach 150–250 KB. The rule: resize to the display dimensions, convert to AVIF/WebP, and set the quality to 80, and you will reach these numbers automatically. Any content image over half a megabyte is usually not optimized.
Does next/image optimize images automatically?
Yes. The next/image component generates srcset/sizes, converts to AVIF/WebP, adds width/height to prevent CLS, and lazy-loads what is below the fold automatically. Your job is to pass the correct dimensions and to set priority on the LCP image to load it early (equivalent to fetchpriority="high" and disabling lazy loading).
What should I do with animated GIFs?
Replace them. GIF is an old, very heavy format (sometimes tens of megabytes). Convert them to a <video> in WebM/MP4 format (with autoplay muted loop playsinline) or to animated AVIF/WebP; the savings reach 90% of the weight, with better quality.
Is using a CDN enough without compressing images?
No. A CDN brings the image geographically closer, but it does not fix a 3 MB image; it stays heavy, just closer. The right order: compress and resize first, then deliver through a CDN. Best of all is an image CDN that converts and resizes on demand, combining both. See What is a CDN for details.
How do I actually measure the improvement from optimizing images?
Run PageSpeed Insights and watch LCP and the "Serve images in next-gen formats" and "Properly size images" recommendations, or open DevTools > Network and sort by size to see the heaviest images before and after. Compare LCP and CLS before and after optimizing; the improvement should be noticeable in both numbers.
Does optimizing images help SEO?
Yes, in two ways: directly, by improving Core Web Vitals (a ranking signal in page experience), and indirectly, through descriptive alt text and meaningful file names that help the search engine understand the image and index it in image search. A faster site is also crawled more deeply and keeps visitors longer.