Website Image Optimization: Dimensions, Compression, Formats, Quality and Delivery Explained
Choose format and quality by measurement instead of by rule, find the real display size at each breakpoint, and get srcset and sizes right.
In short
Images are usually the largest thing on a web page, and "optimise your images" is usually taken to mean "compress them". Compression is the third most important thing, not the first.
In order of how much they actually save:
- Dimensions — do not send a 3000-pixel image into a 600-pixel space.
- Format — AVIF and WebP are substantially smaller than JPEG at the same visual quality.
- Compression — find the quality level where nobody can see a difference.
- Delivery — the right file for the right screen, loaded in the right order.
Get the first one right and you will often save more than the other three combined.
Dimensions: the part that matters most
A browser downloads every byte of an image before it can scale it down. A 3000 × 2000 photo displayed in a 600-pixel-wide box costs you the full file and then throws away most of the detail.
Finding the real displayed size
- Open your page in Chrome, open DevTools.
- Set the viewport to a phone width using the device toolbar.
- In the Elements panel, hover the image.
- Chrome shows two numbers: intrinsic size (the file) and rendered size (the space).
What you should see: intrinsic size roughly equal to rendered size multiplied by the device pixel ratio you want to support. If intrinsic is far larger, that gap is pure waste.
Repeat at tablet and desktop widths. The largest rendered width across your breakpoints is the largest file you need.
Device pixel ratio
Modern phones pack two or three physical pixels into each CSS pixel, so a 600-pixel-wide box wants roughly 1200 pixels of image to look sharp. Not 3000.
There are diminishing returns above about 2×: the difference between 2× and 3× is very hard to see and costs a lot of bytes. Serving 2× is a reasonable default.
Format: what each one is actually for
| Format | Use it for | Notes |
|---|---|---|
| AVIF | Photographs, where you want the smallest file | Smallest at equal quality. Slower to encode. |
| WebP | Photographs, broad compatibility | Larger than AVIF, smaller than JPEG. Supports transparency. |
| JPEG | A fallback for photographs | Universally supported. Largest of the three. |
| PNG | Images needing exact pixels, or flat colour with transparency | Lossless, so photographs become very large. |
| SVG | Logos, icons, line art, diagrams | Vector: scales to any size, usually tiny. |
Two practical rules. Photographs should not be PNG — it is lossless, so a photo stays enormous. And logos and icons should be SVG — converting a logo to WebP is solving the wrong problem.
Serving a modern format with a fallback
<picture>
<source type="image/avif" srcset="/hero.avif">
<source type="image/webp" srcset="/hero.webp">
<img src="/hero.jpg" width="1200" height="800" alt="..." fetchpriority="high">
</picture>
The browser takes the first format it understands. If you use an image CDN, it can usually do this negotiation for you from a single URL, which is simpler to maintain.
Compression: by testing, not by rule
Lossy compression discards detail. The question is how much you can discard before anyone notices, and the answer differs per image — a photograph of a textured fabric tolerates far less than a soft-focus landscape.
So "always use quality 80" is a rule that is too aggressive for some images and leaves bytes on the table for others.
The method
- Export at a high quality as your reference.
- Export again at a noticeably lower quality.
- Compare them at full size, on a good screen, side by side.
- Step the quality up until the difference disappears, then take one step further for safety.
- Note the number, and use it as your starting point for similar images.
# Compare a few quality levels so you can look at them side by side
for q in 60 70 80 90; do
cwebp -q $q hero.png -o "hero-q$q.webp"
done
ls -lh hero-q*.webp
What you should see: a file size curve that flattens. Past a certain quality you are paying significantly more bytes for a difference you cannot see; below it, artefacts appear quickly.
Delivery: the right file for the right screen
srcset and sizes
srcset lists the files you have. sizes tells the browser how wide the image will be, so it can choose.
<img
src="/product-800.webp"
srcset="/product-400.webp 400w, /product-800.webp 800w, /product-1200.webp 1200w, /product-1600.webp 1600w"
sizes="(min-width: 990px) 50vw, 100vw"
width="1600" height="1067"
alt="..."
>
sizes is the part almost everyone gets wrong, and getting it wrong undoes the whole exercise. The browser picks a file before your CSS has loaded, so it has nothing to go on except what you tell it here. If sizes says 100vw while the image actually occupies half the screen on desktop, the browser downloads roughly twice the pixels it needs — and your correct srcset achieves nothing.
Describe your real layout, breakpoint by breakpoint. Check it afterwards by comparing intrinsic and rendered sizes at each width.
width and height are not optional
Always set them. They let the browser reserve the correct space before the file arrives, which prevents the page jumping as images load. CSS still controls the displayed size.
<img src="/photo.webp" width="1200" height="800" alt="..." style="width: 100%; height: auto">
Loading priority
One image per page — your largest visible one — should load eagerly and at high priority. Everything below the fold should be lazy. Getting this backwards is one of the most common self-inflicted performance problems.
<!-- The main image: no lazy, high priority -->
<img src="/hero.webp" fetchpriority="high" width="1200" height="600" alt="...">
<!-- Further down the page -->
<img src="/gallery-3.webp" loading="lazy" width="800" height="600" alt="...">
An image CDN
An image CDN resizes, converts and compresses on request from a single original, and serves from somewhere near your visitor. It removes most of the manual work above and is usually the right answer for any site with a lot of images. Many platforms include one.
Platform differences
Shopify. The image CDN resizes and converts for you, so uploading a large original is correct — the work is in requesting the right width in your theme. Use image_url with a width and the image_tag filter, which also emits width and height.
WordPress. Registered image sizes handle much of this if the theme uses them. The common failures are page builders that strip dimensions, uploading originals straight from a camera, and lazy loading applied to the hero.
Custom builds. Either an image CDN or a build-time pipeline that generates sizes and formats. Doing it by hand per image does not survive contact with a content team.
Hosted builders (Wix, Squarespace). The platform handles conversion and serving, and you usually cannot control loading behaviour. What you can control is what you upload — and on these platforms that is often the only lever available, which makes it a real one.
Common mistakes
Compressing an image whose dimensions are wrong. Treating the symptom.
A sizes value that does not match the layout — the most common cause of a phone downloading a desktop file.
Photographs as PNG.
Converting logos and icons to WebP instead of using SVG.
Lazy-loading the main image.
Marking several images high priority. They compete, and the real one arrives later.
Judging quality at a small size on a low-density screen.
Optimising once. Without a limit at the point images are uploaded, the problem returns within months.
Stripping width and height to "let CSS handle it", which reintroduces layout shift.
Verification
- Compare intrinsic and rendered sizes in the Elements panel at every breakpoint. They should now be close, allowing for pixel ratio.
- Check transferred size in the Network panel, cold cache, and confirm the format is what you expect.
- Look at the image at full size on a high-density screen next to the original. If it looks worse, you went too far.
- Confirm the main image still loads eagerly and the rest are deferred: reload without scrolling and check what was requested.
- Check LCP — it should improve if the main image was your bottleneck. If it did not, your cost was discovery or rendering, not bytes.
- Check CLS — dimensions should have removed any shift as images load.
- Then watch field data over the following four weeks.
When it still does not improve
- Files are smaller but LCP has not moved → your cost was not download. The browser may be discovering the image late, or something may be blocking the render.
- A phone still downloads the large file → your
sizesattribute is wrong. This is almost always the cause. - The image looks soft on a phone → you are serving below 2× for that breakpoint. Add a larger candidate to
srcset. - AVIF is not being served → check your server sends the right content type, and that your
<picture>source order puts AVIF first. - It regressed a month later → new images were uploaded without the pipeline. This is a process problem, not a technical one.
Keeping it fixed
Image weight returns the moment someone uploads a photo straight from a camera.
Three things that hold: an automated step that resizes and converts on upload or at build, a documented maximum upload dimension that whoever adds content knows about, and a page-weight check before release so a regression is caught by you rather than by a visitor.
Frequently asked questions
What is the best image format for a website?
AVIF for photographs where you want the smallest file, WebP where you want broad compatibility, and SVG for logos, icons and line art. Keep PNG only for images needing exact pixels or flat colour with transparency — a photograph saved as PNG stays enormous.
How do I know what size my images should be?
Open DevTools, hover the image in the Elements panel, and compare its intrinsic size with its rendered size at each breakpoint. Multiply the largest rendered width by about 2 for high-density screens. If intrinsic is far larger than that, the difference is waste.
What image quality setting should I use?
There is no single right number — it differs per image. Export a reference at high quality, export again lower, compare at full size on a good screen, and step up until the difference disappears. A fabric texture tolerates far less compression than a soft-focus landscape.
Why is my phone still downloading the large image?
Almost always a wrong sizes attribute. The browser picks a file before your CSS loads, so sizes is all it has to go on. If it says 100vw when the image occupies half the screen on desktop, the browser downloads roughly twice the pixels it needs and your srcset achieves nothing.
Do I still need width and height on images?
Yes, always. They let the browser reserve the correct space before the file arrives, which prevents the page jumping as images load. CSS still controls the displayed size. Removing them to "let CSS handle it" reintroduces layout shift.
Is compression or resizing more important?
Resizing, by a wide margin. An image at the wrong dimensions wastes far more than one in the wrong format or at a slightly high quality. Fix dimensions first, then format, then compression.
References
- Optimize images — web.dev
- Responsive images — MDN
- The picture element — MDN
- Optimize Largest Contentful Paint — web.dev