Most images on the web carry far more data than a visitor can see. The aim is to remove that surplus and stop just before the picture starts to look worse. This guide gives you a method that works for any image and any tool.
What compression removes
There are two kinds. Lossless compression packs the same pixels more tightly, so the image is identical when it is opened. Lossy compression discards detail the eye is least likely to notice, such as fine colour variation in busy areas, and can make a file many times smaller.
"Without visible loss" nearly always means lossy compression at a setting where you cannot see the change at normal viewing size. That point is different for every image, which is why a fixed quality number is a starting point and not an answer.
Step by step
- Keep the original. Work on a copy. Every lossy save discards a little more, so always compress from the source file, never from one that has already been compressed.
- Resize to the size it is shown at. Find the widest the image appears on your page, in CSS pixels, and double it to cover high-density screens. A photo shown 800 pixels wide needs to be about 1600 pixels wide, not the 4000 or more that a camera produces. This step often saves more than everything that follows.
- Pick the format for the content. Photos suit JPEG, WebP or AVIF. Logos, icons and screenshots, with sharp edges and flat colour, suit PNG, lossless WebP or SVG. Our format guide covers the choice in detail.
- Compress at a middle setting. Start around quality 75 for JPEG or WebP. Quality numbers are not comparable between formats or tools, so treat the number as a dial, not a measurement.
- Compare with the original at full size. Put the result next to the source at 100% zoom and check the places that fail first, listed below.
- Adjust. If you cannot see a difference, lower the quality and compare again. When you can just see one, go back up a step. That is the setting for this image.
Where quality loss shows first
- Smooth gradients, such as skies and studio backdrops, break into visible bands.
- Sharp edges and text pick up faint halos or smudges.
- Skin and other subtle textures turn waxy or blotchy.
- Saturated colour next to a contrasting colour, such as red lettering on white, loses its crisp edge, because lossy formats usually store colour at a lower resolution than brightness.
An image with none of these will tolerate much stronger compression than one that has them.
Smaller gains worth taking
- Remove metadata. Camera files carry settings, a thumbnail and sometimes the place the photo was taken. Most compressors drop this when they re-encode. It saves a little space and avoids publishing a location by accident.
- Use progressive JPEG for larger photos. The file is often slightly smaller, and the picture appears whole and then sharpens instead of arriving from top to bottom.
- Do not enlarge. Scaling a small image up adds bytes without adding detail.
Doing it for many images
Judging every image by eye does not scale to a whole site. Settle on a quality setting using a handful of your most demanding images, the ones with gradients, faces or fine text, and apply it to the rest. Then spot-check a few results. Images that are less demanding simply come out smaller.
Keep the originals somewhere outside the website. When a better format or encoder comes along, you will want to compress from the source again, not from today's output.
Try it
SquishPixel compresses JPEG, PNG, WebP and AVIF files in your browser, so nothing is uploaded. Add your images, choose a quality setting, and compare each result with its original before you download.