Skip to article
PerformanceMar 24, 20253 min read

Image optimization: formats, responsive sizes and lazy loading

Choose image formats and dimensions, configure srcset and sizes, and use lazy loading for offscreen images without delaying the LCP image.

Image optimization: formats, responsive sizes and lazy loading

Why image optimization is important

Large or late-loading images can delay the main content and worsen LCP. Start with the images actually loaded by the page and measure their contribution. Smaller transfers can improve loading, but do not guarantee search rankings or a particular conversion increase.

Choosing an image format

Compare JPEG, PNG, WebP and AVIF using representative images and an acceptable visual quality level. The smallest result depends on the image, encoder and settings. Check the browsers you support and provide a fallback when needed. SVG is useful for suitable vector artwork.

FormatStrengthsTrade-offsTypical uses
JPEGOften efficient for photographsLossy compression; no alpha transparencyPhotos
PNGLossless encoding and transparencyCan be large for photosGraphics requiring lossless detail
WebPLossy or lossless encoding, transparencyVerify older target browsers and actual file sizePhotos, graphics, animation
AVIFCan compress well at useful qualityEncoding cost and target-browser support need checkingPhotos and graphics
SVGScales as vector artworkNot a replacement for photographic raster imagesIcons, logos, illustrations

Responsive images: srcset and sizes

Use srcset to list image candidates and sizes to describe their rendered width. The browser chooses a candidate using that information and device conditions. The slot widths below are examples: match them to your actual CSS. This example is for an offscreen image; replace the illustrative alt text with an appropriate description and use the real aspect ratio.

<img
	src="example-400w.jpg"
	srcset="example-400w.jpg 400w, example-800w.jpg 800w, example-1200w.jpg 1200w"
	sizes="(max-width: 600px) 400px, (max-width: 1200px) 800px, 1200px"
	alt="Mountain lake"
	width="1200"
	height="800"
	loading="lazy"
/>

Lazy loading for offscreen images

loading="lazy" lets the browser defer an offscreen image until it approaches the viewport. It may start loading before the image becomes visible. The exact timing depends on the browser and conditions.

  • Deferring non-critical images can save initial transfer and reduce competing requests.
  • Do not lazy-load the main above-the-fold image, particularly the likely LCP image. Delaying that image can worsen LCP rather than improve it.
  • Reserve space with suitable dimensions or an aspect ratio to reduce layout shifts.

Example for an image below the initial viewport. The dimensions are illustrative; use those of the actual file:

<img src="example.webp" alt="Mountain lake" width="1200" height="800" loading="lazy" />

Tools and services for optimization

ToolDescriptionLink
TinyPNGOnline service for compressing PNGs and JPEGsTinyPNG
ImageOptimImage Optimization on macOSImageOptim
SquooshA powerful tool from GoogleSquoosh

Practical tips and examples

  1. Compare formats at an acceptable visual quality; add a fallback where needed.
  2. Match srcset candidates and sizes to the actual layout and device needs.
  3. Apply loading="lazy" to offscreen images, keeping the likely LCP image eager. Native lazy loading usually needs no Intersection Observer; custom behavior should solve a specific requirement.
  4. Automate resizing and compression in the build or delivery pipeline, then inspect the output.
  5. Compare PageSpeed Insights and relevant Web Vitals before and after, including LCP and CLS, under comparable conditions.

Verify the published result

Check the requested image candidate, transferred bytes, visual quality and loading priority. Repeat on representative mobile and desktop layouts. Confirm that the main image appears promptly and the layout remains stable.

Reduce unnecessary bytes while preserving the content and visual quality the reader needs.

Use our speed audit to investigate a page, then verify the specific image changes in the browser. Record measured improvements separately from untested assumptions.

Website speed check

Find out what slows your website down

Check your page with Milten to see its Core Web Vitals and get recommendations for faster loading.

Check your website
Cookies

We use cookies

We use cookies to give you a better experience on our site. You can learn more about how we use cookies in our privacy policy.