A multi-megabyte image can be perfect for print and completely disproportionate for a web page. Optimization does not mean degrading an image until it becomes small. It means removing what the final display does not need: excessive dimensions, an unsuitable format, unnecessarily high quality or metadata that adds no value.
A practical order is: resize, choose the format, compress, inspect visually, then serve the right variant to the browser.
1. Start with dimensions
This is often the biggest win.
A 6000 × 4000 photo contains 24 million pixels. If the page never displays it wider than 1200 pixels, downloading and decoding the full-resolution source wastes resources.
Ask:
- what is the maximum displayed width?
- is there a mobile variant?
- do high-density screens matter?
- can the user open a full-size version?
An image displayed at 800 px wide rarely needs a 6000 px source.
2. Dimensions and file size are different things
Two 1600 × 900 images can have very different file sizes. Dimensions describe pixel count; file size also depends on format, image content and compression settings.
A detailed photograph compresses differently from a logo with a few flat colours. One preset for every image is rarely optimal.
3. Choose the format for the content
| Content | Common choice | Reason |
|---|---|---|
| Photography | WebP, AVIF, JPEG | efficient lossy compression |
| UI screenshot | WebP or PNG | sharp edges and flat areas |
| Vector logo / icon | SVG | resolution-independent |
| Transparency | WebP, AVIF, PNG | alpha channel |
| Maximum compatibility | JPEG / PNG | long-established support |
WebP is widely supported and handles lossy/lossless compression, transparency and animation. AVIF also offers strong compression and modern capabilities. JPEG and PNG remain useful as simple sources or fallbacks.
4. Lossy or lossless?
Lossless compression preserves the original pixel data exactly. Lossy compression discards information considered less perceptually important.
For web photography, sensible lossy compression can reduce file size dramatically without an obvious difference at normal display size.
The best setting is not “quality 100”. It is the lowest setting that still looks correct for the real use case.
5. Inspect at real display size
Do not judge a web image only at 400% zoom.
Check it:
- at the size it will actually be displayed;
- on a normal desktop screen;
- in difficult areas such as hair, foliage, gradients, text and fine details;
- on mobile when the asset is important.
If an additional 100 kB reduction is invisible in those conditions, it is likely useful. If it produces halos around text or destroys product details, it is not.
6. Resize before compression
A 4000 × 3000 source contains 12 million pixels. A target of 800 × 600 contains 480,000.
That is a 25× reduction in pixel count.
The final file size will not necessarily shrink by exactly 25×, but the potential gain is substantial. Compressing the giant source first and asking CSS to scale it down later optimizes the wrong file.