How to compress images for a website

Compressing images for a website is three steps in a fixed order: resize each image to the largest width it is displayed at (about twice that for sharp phone and laptop screens), choose the format (WebP or JPG for photos, PNG or SVG for graphics), then compress to a file size that suits the image's role on the page.

Doing them in that order matters: compression alone cannot fix an image that is three times wider than the space it fills.

Why images are the first thing to fix

Google's Search Central documentation puts it plainly: “images are often the largest contributor to overall page size, which can make pages slow and expensive to load.” Every visitor downloads every byte, so the gap between a 3 MB and a 150 KB photo is paid again on every page view.

Step 1: resize to the displayed size

Find how wide the image actually appears in your layout, for example a content column of 800 CSS pixels or a full-width banner. Google's Lighthouse documentation is direct about the rest: “your page should never serve images that are larger than the version that's rendered on the user's screen. Anything larger than that just results in wasted bytes and slows down page load time.” Lighthouse flags an image when it is at least 4 KiB larger than needed.

The one twist is high-density screens. MDN notes that “some devices have high resolution screens that need larger images than you might expect to display nicely”, with two or more device pixels per CSS pixel. So a slot 800 CSS pixels wide wants an image about 1600 pixels wide for those screens, and an 800 px version for the rest. Theimage resizer or the bulk resizer makes both.

Step 2: choose the format by content

A photo saved as PNG is the easiest oversized file to fix. To turn existing JPGs into WebP, use JPG to WebP; for the wider format question, see thebest image format for the web.

Step 3: compress to a budget

Rather than picking a quality number for each image, it is easier to give each kind of image a file-size budget and let a tool find the best quality that fits. Budgets are your call; a hero photo can afford more than a thumbnail in a grid of twenty. Our target-size compressor searches for the highest quality that fits the budget and, if allowed, scales the image down when quality alone is not enough.

Read the table backwards and it tells you something useful: if your slot needs about 1600 px, a budget near 100 KB is realistic for a JPG of this kind; asking for 50 KB means the tool has to shrink it below that width. If you resized in step 1 and the budget suits that size, the compressor keeps your dimensions and only adjusts quality.

Step 4: serve the files sensibly

Compressed files help most when the page asks for the right one. Two HTML features do most of the work:

<img src="team-800.webp"
     srcset="team-800.webp 800w, team-1600.webp 1600w"
     sizes="(max-width: 800px) 100vw, 800px"
     loading="lazy" alt="Our team at the spring workshop">

A whole site's worth of images

For an existing site, the bulk image compressor applies one KB target or one quality to many files and returns a ZIP. Resize the batch first if the originals are camera-sized. If you want to understand what the quality setting throws away, thelossy vs lossless guide explains it.

Sources

  1. Google Images SEO best practices, Google Search Central. Checked December 2026.
  2. Properly size images (Lighthouse), Chrome for Developers (Google). Checked December 2026.
  3. Using responsive images in HTML, MDN Web Docs. Checked December 2026.
  4. Lazy loading, MDN Web Docs. Checked December 2026.
  5. Image file type and format guide, MDN Web Docs. Checked December 2026.
  6. An image format for the Web (WebP), Google for Developers. Checked December 2026.

Browse all image guides