How to optimize images for a website: a step-by-step checklist

Ten steps, in order: resize, pick a format, compress, add responsive sizes, set dimensions, lazy-load below the fold, prioritize the hero, name and describe.

By
Picture Optimizer team
Published
Type
How-to

To optimize images for a website, resize each one to the largest width it is displayed at, save photos as AVIF or WebP (with a JPEG fallback), compress at a quality you have checked by eye, and serve smaller versions to small screens with srcset. Then add width and height, lazy-load images below the first screen, give the main hero image priority, and finish with a descriptive file name and alt text.

Key takeaways

  • Size first, format second, compression third. That order gives the largest savings for the least effort.
  • Responsive sizes stop phones from downloading desktop images.
  • Lazy loading helps images further down the page and hurts the main image at the top.
  • File names and alt text don't change speed, but they help people using screen readers and help search engines understand the image.

1. Find out which images matter

Start with the page, not the media folder. Run your most important pages through PageSpeed Insights or Lighthouse and note the Largest Contentful Paint (LCP) element. According to web.dev, LCP can be an image element, an image inside SVG, a video poster, an element with a CSS background image or a block of text. A good LCP is 2.5 seconds or less at the 75th percentile of page loads.

If the LCP element is an image, that image is your first job.

2. Resize to the displayed width

Check how wide each image actually appears. A hero might fill 1,600 to 2,048 px on a large screen; a blog image might sit in an 800 px column. Export at that width, or up to twice it if you want extra sharpness on high-density screens.

This is usually the biggest win. In our sample run of 54 business photos, the originals had a median of 24 megapixels. Resized to 2,048 px wide, they kept about 15% of their pixels.

3. Choose the format

MDN's image format guide recommends WebP or AVIF for raster images because they generally compress better than PNG, JPEG and GIF, lossless encoding for screenshots, diagrams and logos, and lossy compression for photographs.

  • Photos: AVIF or WebP, with JPEG as a fallback.
  • Graphics with sharp edges or transparency: lossless WebP, PNG or SVG.
  • Logos and icons: SVG when you have vector files.

Google Images can index BMP, GIF, JPEG, PNG, WebP, SVG and AVIF, according to Google's image SEO documentation, so modern formats are not a search risk.

4. Compress at a checked quality

Export one representative photo at two or three quality settings, compare each with the original at 100% zoom, and use the lowest setting where you can't see a difference. For many photos at once, a metric like SSIM helps you spot outliers. In our sample run, AVIF at our High preset kept an SSIM of 0.99 or higher for all 54 photos while the total fell from 183.0 MB to 16.2 MB.

5. Serve responsive sizes with srcset

A phone showing an image 400 px wide does not need a 2,048 px file. The srcset and sizes attributes let the browser choose:

```html
<img
srcset="plumber-768.avif 768w, plumber-1024.avif 1024w, plumber-2048.avif 2048w"
sizes="(width <= 800px) 100vw, 800px"
src="plumber-1024.avif"
alt="Plumber repairing drain pipes under a kitchen sink"
width="1024" height="768">
```

MDN explains the "w" descriptor as the image's intrinsic width in pixels, and sizes as the width of the slot the image fills under each media condition. If you need different crops for different screens, use the picture element (MDN calls this art direction).

For a sense of scale, the plumber photo from our run was 23 KB at 1,024 px, 17 KB at 768 px and 7 KB at 300 px as AVIF.

6. Always set width and height

web.dev recommends width and height attributes on images so the browser can reserve space before the file arrives. Without them, text jumps as images load, which counts against Cumulative Layout Shift.

7. Lazy-load images below the first screen

Add loading="lazy" to images that start off-screen. web.dev lists support in Chrome 77+, Edge 79+, Firefox 121+ and Safari 16.4+, and browsers that ignore the attribute simply load the image normally.

Do not lazy-load images that are likely to be visible when the page opens. web.dev is explicit: never lazy-load your LCP image.

8. Give the hero image priority

For the LCP image, web.dev recommends making it discoverable early and loading it with high priority, for example fetchpriority="high" on the img element, or a preload with high fetch priority when the image is set in CSS. web.dev breaks LCP into four parts (time to first byte, resource load delay, resource load duration and element render delay) and suggests that load delay and render delay should each stay under about 10% of the total. A smaller, correctly sized file shortens the load duration part directly.

9. Name files descriptively

Google's image documentation says a file name can give Google "very light clues" about an image, and gives an example: my-new-black-kitten.jpg is better than IMG00023.JPG. It is a small signal, but it costs nothing. Use short, lowercase, hyphenated words that describe the image.

10. Write alt text

Alt text is for people who can't see the image first, and search engines second. The W3C alt decision tree covers the cases: describe informative images briefly, describe the destination for linked images, repeat the text for images of text, and use an empty alt="" for purely decorative images. Google's guidance prefers specific descriptions ("Dalmatian puppy playing fetch") over single words or keyword lists.

Check your work

Re-run PageSpeed Insights or Lighthouse after the changes and compare LCP and total image weight. Field data from real visitors updates more slowly than lab tests, so expect lab results first.

Doing this without a dozen tools

Steps 2 to 5, 9 and 10 can run in one pass. Our website image optimization workflow resizes, converts and compresses photos, and on Starter and up also writes responsive sizes (150, 300, 768 and 1,024 px) plus AI alt text, titles and file names you review before export. The Free plan compresses your first 15 photos, once, to AVIF or JPG. See responsive images for how the sizes are made, or the alt text generator for the text side.

Keep reading

Sources

Questions

Short answers to what people ask about this.

Resizing to the width the image is actually displayed at. Uploading camera-sized photos is the most common cause of heavy pages, and no compression setting fully makes up for it.