Skip to content
Image Compressor

How to optimize images for web performance

To optimize images for web pages, you need to send each visitor the smallest file that still looks sharp on their screen, and load it at the right moment. Images are usually the heaviest part of a page, so getting them right is one of the most effective ways to make a site faster. This guide covers the essentials in the order that saves the most.

Why images matter so much

On a typical web page, images account for a large share of the bytes a visitor downloads, often more than scripts, styles and fonts combined. A single unoptimized hero photo straight from a camera can weigh more than the rest of the page together.

Large images hurt most on phones and slow connections, which is exactly where many visitors are. They also affect how search engines judge a page, because loading speed is part of how page experience is measured.

Core Web Vitals basics

Google’s Core Web Vitals are three measurements of real visitors’ experience. A page passes when at least 75% of visits meet the threshold for each one.

  • Largest Contentful Paint (LCP): how long the biggest visible element takes to appear. Good is 2.5 seconds or less. On many pages that element is an image.
  • Cumulative Layout Shift (CLS): how much the content jumps around while loading. Good is 0.1 or less. Images without reserved space are a classic cause.
  • Interaction to Next Paint (INP): how quickly the page reacts to taps and clicks. Good is 200 milliseconds or less. Images affect it less directly, but heavy pages keep the browser busy.

You can check all three for free in PageSpeed Insights, which shows both real-visitor data, when Google has enough of it, and a lab test from Lighthouse.

Serve the right dimensions

The single biggest waste is sending an image far larger than it is displayed. A 4000-pixel photo shown in a 600-pixel column still makes every visitor download all 4000 pixels. Resize images to the largest size they are actually shown at, multiplied by two for sharp display on high-density phone and laptop screens.

Responsive images let the browser choose. With the srcset and sizes attributes you offer several widths of the same picture, and each device downloads only the one it needs. Most content management systems and image services generate these versions for you.

  • Full-width hero images: about 1920 to 2560 pixels wide for large screens, with smaller versions for phones.
  • Images inside an article column: about 1200 to 1600 pixels wide.
  • Thumbnails and cards: often 400 to 800 pixels wide.

The compressor on this site has resize presets from 1024 to 3840 pixels on the longest side, which covers the common cases when you prepare files by hand.

Choose modern formats and sensible quality

WebP is supported by all current major browsers and is typically 25 to 35% smaller than JPG at similar quality. AVIF is often smaller still. With the picture element you can offer AVIF or WebP first and a JPG fallback, and each browser picks the best format it understands.

For photos, a quality of 70 to 80 is usually indistinguishable from the original at normal viewing size. Keep PNG for screenshots and graphics with sharp edges, and use SVG for logos and icons, which stay crisp at any size and are often tiny. Batch-converting and compressing a folder of photos in the browser is a quick way to test the difference before you change a whole site.

Load images at the right moment

Images below the fold do not need to load until the visitor scrolls near them. Setting the loading attribute to lazy on those images tells the browser to wait, which speeds up the first view and saves data for visitors who never scroll that far.

Never lazy-load the main image at the top of the page: that delays exactly the element LCP measures. Load it normally, and consider setting its fetchpriority attribute to high so the browser requests it early.

To prevent layout shifts, always give images width and height attributes, or a CSS aspect ratio. The browser can then reserve the right space before the file arrives, and the text does not jump when it loads.

Delivery and caching

Once images are the right size and format, make sure they are delivered efficiently. Serve them with long cache lifetimes so returning visitors do not download them again, and from a content delivery network close to your visitors.

Image CDNs and many hosting platforms can resize, convert and compress images on the fly based on the visitor’s device. If you use WordPress or a similar CMS, recent versions already create several sizes for each upload and add lazy loading automatically; a good optimization plugin can handle format conversion. Removing camera metadata, which adds a few kilobytes per image and can reveal where a photo was taken, is a useful extra.

A practical workflow

If you are improving an existing site, work from measurements rather than guesses.

  1. Run the page through PageSpeed Insights and note the LCP element and any image warnings.
  2. Open your browser’s developer tools, go to the Network tab, filter by images and sort by size to find the heaviest files.
  3. Resize each heavy image to the largest size it is displayed at, times two.
  4. Compress it as WebP or AVIF at a quality around 75, keeping a JPG version as a fallback if needed.
  5. Add width and height attributes, lazy-load images below the fold and prioritize the main image.
  6. Replace the files, clear any caches and measure again to confirm the improvement.

Frequently asked questions

What is the best image size for a website?

There is no single size: match the largest width the image is displayed at, doubled for high-density screens. In practice that is about 1200 to 1600 pixels for content images and up to 2560 for full-width heroes.

Should I use WebP or AVIF on my site?

Both are well supported in current browsers. AVIF is often smaller but slower to encode; WebP is a safe default. Using the picture element with a JPG fallback lets you serve the best format to each browser.

Does lazy loading help SEO?

Indirectly, by making pages faster. Search engines can still find lazy-loaded images when you use the standard loading attribute, but do not lazy-load the main image at the top of the page.

How small should a web image file be?

As a rough target, most content images can be under 200 KB and thumbnails well under 50 KB. Hero images may be larger, but anything over 500 KB deserves a second look.

More guides