To reduce image file size on a website, start with the files the browser actually downloads, not the exports sitting on your desktop. Check the Network panel for oversized requests, match dimensions to the rendered layout, pick a format suited to the content, and confirm the browser selects the smaller file after deployment. Skipping any step can leave a page serving the old, larger asset.
How do you reduce image file size on a website?
Open the page in a browser with a defined viewport and a cleared cache, then filter the Network panel to images. Sort by transfer size and note which requests are largest. Separate the hero image, in-content photos and off-screen media, because each may need a different fix.
- →Identify the largest image requests on the page.
- →Record the delivered width, height and file size for each one.
- →Decide whether the asset needs a dimension change, a format change, or both.
- →Replace the file, then reload under the same conditions to confirm the change took effect.
How to choose the right image dimensions for your layout
Match the exported image to the size it is actually rendered at, accounting for display density. Serving a desktop-sized image to a phone wastes bandwidth: desktop images displayed on mobile layouts can transfer roughly two to four times more data than the layout needs, because the browser downloads pixels it never shows.
Illustrative example, not a measured test: an image displayed at 500 CSS pixels wide might have 500-pixel and 1000-pixel exports available, so a standard screen loads the smaller file and a high-density screen loads the larger one. Check which candidate your own browser requests for your own layout; do not assume the same breakpoints apply to a different design.
When should you use modern image formats like WebP or AVIF?
WebP and AVIF generally compress photographic content more efficiently than PNG or JPEG at a comparable visual quality, so switching a large photo to one of these formats is often the single biggest win available on a page.
Encoding and decoding support varies by browser and by tool. A browser that can display an AVIF image is not guaranteed to encode one, so test the actual output file rather than assuming support. Do not expect a TIFF export to open correctly in every browser.
For icons, logos and simple illustrations with few colors, SVG is usually the better choice: it is resolution-independent and typically smaller than an equivalent bitmap, though minifying an SVG only strips comments and whitespace rather than fully optimizing the underlying paths.
| Format | Good for | Limitation |
|---|---|---|
| JPEG | Photographs without transparency | Lossy even at high quality; not pixel-identical to the source |
| PNG | Images needing transparency or flat color | Larger files for complex photographs |
| WebP | Photographs and graphics needing smaller files | Browser encode and decode support varies |
| AVIF | Photographs where compression matters most | Decode support is wider than encode support |
| SVG | Icons, logos, simple illustrations | Not suited to photographic detail |
How to use srcset and sizes to serve responsive images
The srcset attribute lists several image sources at different widths, and the browser picks the most appropriate one based on the device's viewport width and pixel density.
The sizes attribute tells the browser how the image will be laid out at different viewport widths, so it can make that choice before the layout is finalized. Without accurate sizes information, the browser may still select a candidate that is larger than necessary.
After adding srcset, reload the page in the browser's responsive design mode at a few widths and check in the Network panel which file was actually requested. If the browser keeps choosing the largest candidate, the sizes value is likely wrong rather than the srcset list itself.
Should you use lazy loading for images below the fold?
Lazy loading defers requests for images until they are near the viewport, which reduces how much image weight the browser has to download on first load.
Lazy loading only helps images that are not visible when the page first renders. Never apply it to the largest contentful paint image; delaying that request makes the page appear to load more slowly, not less.
How to balance image compression and visual quality
For lossy formats such as JPEG, lower the quality setting gradually and compare the result against the original at the size it will actually be displayed, rather than at full resolution on a large monitor.
JPEG stays lossy even at a high quality setting, and a result that looks visually lossless on screen is not pixel-identical to the source. Re-encoding a raster image also typically drops embedded metadata such as ICC color profiles or GPS coordinates, while an SVG or a file that passes through unchanged may retain it; check the output rather than assuming metadata was removed.
How to check the result after deployment
Replace the referenced file, then reload the live page under the same viewport and cache conditions used earlier. Inspect the actual content type and transfer size of the request rather than trusting the file extension. Smaller image bytes can help pages that are limited by image download time, but they do not reduce server response time on their own, and they will not fix a layout shift unless the layout also reserves space for the image.
Start with the request that transfers the most bytes on your slowest page, fix one of the areas above, then redeploy and recheck the Network panel before moving on to the next image.