About Contact Careers Launching Soon System Status Legal

Article · Getting Online

How to Optimise Website Images for Faster Loading

Oversized images are an easy way to slow a page down, and one of the easier things to fix. The steps are to resize, choose a good format, compress, set dimensions and load the right images at the right time. This article explains each one and who it helps.

Why images matter for speed

Images affect two of the numbers in Core Web Vitals. The first is Largest Contentful Paint, the time it takes the biggest item on the screen to appear, which can be an image at the top of the page. web.dev's guide to optimising LCP says to aim for 2.5 seconds or less for at least 75% of page visits. The second is Cumulative Layout Shift, which images cause when they load without reserved space.

web.dev also notes that image download time is not the main bottleneck for most sites, so check your own results before spending hours on it. Our Core Web Vitals article shows where to look.

Choose the right format

web.dev's guide to image performance describes the main formats:

Format Compression Best for
JPEG Lossy Photographs
PNG Lossless Images where nothing can be lost
WebP Lossy or lossless Most images; widely supported and often smaller than JPEG, PNG or GIF
AVIF Lossy or lossless Photos where you want the smallest files; support is decent but not as broad as WebP
SVG Vector (text-based) Logos, line art, diagrams and charts, not photos

The same guide says some tests showed AVIF files more than 50% smaller than JPEG. Treat that as an upper example, not a promise.

Resize, then compress

  1. Resize to the displayed size. The guide explains that a container 500 pixels wide on a screen with a pixel density of 2 needs an image 1,000 pixels wide. For example, a 4,000-pixel photo shown at 500 pixels sends far more data than the screen can use.
  2. Compress. Lossy compression gives smaller files and suits photos. It is less suited to text and line art, where artefacts can show, so look at the result. Lossless compression removes no data.
  3. Try more than one setting. The guide says there is no universal setting and recommends balancing quality against file size. It names Squoosh and ImageOptim as tools.

Serve the right size to each screen

The srcset attribute lists several versions of an image, and the browser picks one. The sizes attribute says how wide the image will be shown. web.dev warns that width descriptors in srcset do not work without sizes. The <picture> element lets you offer AVIF first, then WebP, with JPEG as a fallback.

More versions mean more files to store and cache, so the guide suggests a reasonable number and measuring the effect.

Stop the page jumping

web.dev's guide to layout shifts says to always include width and height attributes on images and video. Browsers use them to work out the aspect ratio and reserve the space before the image loads. It also suggests the CSS aspect-ratio property as an alternative. The guide says to aim for a CLS of 0.1 or less for at least 75% of page visits, and calls a score above 0.25 poor.

Lazy-load carefully

Adding loading="lazy" delays an image until it is in or near the screen, which saves data and lets the important content load first. Use it for images further down the page.

Do not use it on the main image at the top. web.dev says plainly: never lazy-load your LCP image, because it delays the image and hurts LCP. For that image the guide suggests fetchpriority="high", but warns that setting high priority on more than one or two images makes it unhelpful.

A short checklist

  • Resize every image before uploading.
  • Use WebP, or AVIF with a fallback, for photos.
  • Compress and look at the result.
  • Add width, height and descriptive alt text (see accessibility basics).
  • Lazy-load below-the-fold images only.
  • Re-test with PageSpeed Insights, as in our website launch checklist.

An image CDN can automate sizing and formats, as web.dev notes. See what a CDN is and whether you need one.

FAQ

What size should website images be?

It depends on where they are shown. Match the width to the space on the page, allowing for the pixel density of phones and laptops, as in the 500-pixel example above.

Is WebP better than JPEG?

web.dev says WebP is widely supported and often compresses better than JPEG, PNG or GIF. Check each file, because results vary by image.

Should I lazy-load every image?

No. Lazy-load images below the first screen, and leave the main image at the top to load normally.

Related reading