Blog · 7 min read

How to optimize website images for speed and SEO

Published

How to optimize website images for speed and SEO

Images are usually the heaviest part of a web page. A few oversized photos can make a site feel slow, hurt your Core Web Vitals and push visitors away before they read a word. The good news is that image fixes are quick and the gains are large.

This applies to every platform, whether your site runs on WordPress, Shopify, Wix, Squarespace, Webflow or custom code. The rules are the same everywhere.

Why images matter for speed and SEO

Step 1: find your heaviest images

Run your key pages through the page speed checker and look at the biggest files. Anything over about 200 KB deserves a look, and a photo of several megabytes straight from a phone or camera is almost always the culprit. The Core Web Vitals guide explains the other speed factors.

Step 2: resize to the size you display

Do not upload a 4000-pixel photo to show it 800 pixels wide. Resize it to roughly twice the largest size it appears on screen (for sharp display on high-density screens) before uploading. This single step often cuts a file by 90 percent.

Step 3: choose the right format

Step 4: compress

Compression removes data you cannot see. Quality around 75 to 85 percent is usually indistinguishable from the original. Free desktop and online tools can do this, and most platforms and plugins can compress automatically on upload.

Step 5: set width and height

Always give each image its dimensions so the browser reserves space before it loads:

<img src="red-shoes.webp" width="800" height="600" alt="Red running shoes on a white background">

This stops the page from jumping around while images arrive.

Step 6: lazy load, but not the first image

Add loading="lazy" to images further down the page so they load only when a visitor scrolls near them. Do not lazy load the main image at the top, since that delays the most important paint. For that one, use fetchpriority="high" instead.

Step 7: serve the right size to each screen

Use srcset and sizes so phones download a small version and large screens get a bigger one. Most modern platforms generate these for you; check the page source to confirm.

Step 8: name files and write alt text

The on-page SEO checker and the accessibility checker flag images with missing alt text. The accessibility checklist covers the rest.

Step 9: use caching and a CDN

Images rarely change, so let browsers keep them for a long time with cache headers. A content delivery network (CDN) serves them from a location close to each visitor. Confirm your headers with the HTTP header checker.

Watch out for hotlinking and hacked images

If your bandwidth suddenly spikes, other sites may be embedding your images directly. And if unfamiliar image files or folders appear on your server, it can be a sign of a break-in. See how to check if your website is hacked.

Common questions

What is a good image file size for a website?

Aim for under 100 to 200 KB for most content images, and smaller for thumbnails. Full-width hero images can be a little larger if they are compressed well.

Should I switch everything to WebP?

For photos, yes, in most cases. Keep a JPEG fallback only if you must support very old browsers.

Does alt text help rankings?

It helps Google understand the image and the page, and it can bring traffic from image search. Its first purpose is accessibility, so write it for people.

Will compression make my images look bad?

Not at sensible settings. Compare before and after at full size; if you cannot tell the difference, keep the smaller file.

Free tools for this problem

More guides