/

·

No. 021

How to Prepare Images for the Web: Resize, Compress and Pick the Right Format

·

by

A modern, organized workspace with a laptop on a desk

Key takeaways

  • Resize first, compress second, pick the format last. An image that's far bigger than the space it fills wastes more bytes than any compression setting can save.

  • Use JPEG or WebP for photos, PNG or WebP for graphics with sharp edges or transparency, and AVIF for large photos where you can offer a fallback.

  • AVIF works in current Chrome, Firefox and Safari, but it isn't universal, so serve a fallback format to browsers that can't read it.

  • Squoosh runs in your browser and doesn't upload your images. ImageOptim handles whole folders of PNG, JPEG and GIF files on a Mac.

  • Compare the compressed file with the original at full size before you publish. If you can't see a difference, you've found the right setting.

Why image size matters

Images are usually the heaviest part of a web page, and a heavy page loads slowly, especially on a phone. Fixing images is one of the cheapest speed improvements most sites have.

There are three levers, and they work in a fixed order: dimensions, then compression, then format.

Step 1: Resize to the size you need

Start with the dimensions, because they have the biggest effect. A photo straight from a camera or phone can be 4,000 pixels wide or more, while the space it fills on a page might be 800 pixels.

Work out the widest the image will ever be shown, then export at no more than twice that width. Twice covers high-density screens such as most phones and laptops. A photo shown at 800 pixels wide needs a file about 1,600 pixels wide, and nothing larger.

Make the original your master and never overwrite it. Resize a copy so you can always go back.

Step 2: Pick the right format

Each format suits a different kind of image.

Format

Best for

Watch out for

JPEG

Photographs, when you want something every browser and app opens

Larger files than newer formats at the same quality, and no transparency

PNG

Logos, screenshots, line art and anything that needs a transparent background

Large files for photographs

WebP

A default for most web images, both photos and graphics, with transparency

Not every desktop app opens it as easily as JPEG

AVIF

Large photos where file size matters most

Slow to create, and needs a fallback for browsers that can't read it

Browser support is good for all of these. AVIF arrived in Chrome and Opera in 2020, Firefox in 2021 and Safari in 2022, according to Google's web.dev guide. The same guide points out that AVIF "isn't a given across the entire web," and a browser that can't read the file shows a broken image.

The safe way to offer it is a picture element in your page's HTML. It lists an AVIF version, then a WebP version, then a JPEG, and each browser takes the first one it can read. If your site builder or CMS creates these versions for you, check its settings before doing it by hand.

JPEG XL is a newer format that promises smaller files, but reports in 2026 say it still works in only a small share of browsers, so skip it for now.

Step 3: Compress

Compression reduces file size by throwing away detail your eye won't miss. Lossy compression (JPEG, WebP, AVIF) discards more, and lossless compression (PNG, and lossless WebP) keeps every pixel.

For lossy formats, a quality setting of about 75 to 80 is a sensible place to start for photos. Go lower and check, because some images, like smooth skies, show banding sooner than busy scenes.

Squoosh

Squoosh is a free image compressor from Google Chrome Labs. It runs in your browser, and its README says the compression happens locally so your images aren't sent to a server. Drop in an image, pick a format on the right and a quality slider, and watch the file size change. A split view shows the original next to the compressed version so you can see what you lose. It handles one image at a time, which makes it good for hero images and a poor fit for a folder of 200.

ImageOptim

ImageOptim is a free Mac app for batches. Drag in a folder of PNG, JPEG or GIF files and it shrinks them and keeps the folder structure. It doesn't create WebP or AVIF files, so use it for tidying existing images and use Squoosh when you want a new format. Download it from imageoptim.com rather than the App Store.

Photoshop

If you work in Photoshop, use File, then Save a Copy rather than Save for Web or Export As. Adobe added full WebP support in Photoshop 23.2, and the format works for 8-bit RGB documents. Community reports say recent versions list AVIF in the same menu. Neither shows up in Export As or Save for Web (Legacy), so if you can't find them, that's why.

A quick workflow

1. Keep the original untouched and work on a copy.

2. Resize the copy to twice the width it will display at.

3. Choose the format using the table above.

4. Compress it, starting with a quality of 75 to 80.

5. Compare at full size against the original, then lower the quality until you can just see a difference and go back up one step.

6. Name the file for what it shows, such as red-ceramic-mug.webp, and add alt text when you place it on the page.

Mistakes to avoid

  • Uploading the original camera file and letting the page shrink it. The visitor still downloads every byte.

  • Saving a photo as PNG. It's usually far bigger than the same photo saved as a JPEG or WebP.

  • Compressing a JPEG that has already been compressed. Each round loses a bit more, so always start from the original.

  • Using AVIF with no fallback.

  • Leaving out alt text. It describes the image for screen readers and shows when an image fails to load.

Frequently asked questions

What's the best image format for websites?

WebP is a good default for most images, since it handles photos, graphics and transparency in smaller files than JPEG or PNG. Use AVIF for large photos if you can offer a fallback, and JPEG when you need the widest compatibility.

How big should website images be?

No wider than twice the width they're displayed at. An image that fills an 800-pixel column needs a file about 1,600 pixels wide.

Is Squoosh safe to use?

Squoosh's README says images are processed locally in your browser and aren't sent to a server. It does collect some usage data, such as visitor analytics and before-and-after file sizes.

Can I batch compress images for free?

Yes. ImageOptim handles folders of PNG, JPEG and GIF files on a Mac. For WebP or AVIF in bulk, you'll need a different tool or a site builder that converts images for you.