BF50 Black Friday · 50% off all plans
from $5/mo · Auto-applied ---:--:-- Claim 50% off →
Skip to content

Search Seonio

Type a keyword, domain, or paste a URL

Start free with $1 to see full results. Powered by Seonio
Web Development

Image compression: How to make images smaller

Image compression shrinks image files so pages load faster. Pick lossy or lossless, a modern format and the right size, then check the result by eye.

Monthly searches · image compression
1.5m
Keyword research data
image compression
Image compression: How to make images smaller
Click the image to view it full size

Image compression reduces the number of bytes needed to store an image. There are two kinds, and the difference decides almost every choice you make:

  • Lossy compression throws away detail the eye is unlikely to notice. Files get much smaller, but the discarded data is gone for good. JPEG works this way.
  • Lossless compression stores the image more efficiently without changing a single pixel, so it can be rebuilt exactly. PNG works this way.

WebP and AVIF, the newer web formats, can do either: you choose lossy or lossless when you save the file.

Why image size matters for your pages

Images are often the largest part of a page's weight, which can make pages slow and expensive to load, especially on phones. Google Search Central

A large image near the top of the page is also often the biggest thing on screen, which makes it the element measured by Largest Contentful Paint. Google's target for a good LCP is 2.5 seconds or less, and a heavy hero image is one of the easiest ways to miss it.

Lossy or lossless: match it to the image

Photos hide small losses well. Screenshots, text, logos and diagrams don't: lossy compression leaves blur and colored fringes around sharp edges.

The image is... Compression Format to serve
A photo or other image with smooth color changes Lossy AVIF or WebP, with JPEG as the fallback
A screenshot, diagram or image with text Lossless WebP or AVIF lossless, with PNG as the fallback
A logo, icon or chart that must stay sharp at any size None needed SVG
Anything that needs a transparent background Either WebP or AVIF, with PNG as the fallback (JPEG has no transparency)
An animation Lossy A short video (MP4 or WebM) instead of a large GIF

How much smaller the modern formats are

MDN's format guide gives these averages for images of similar visual quality MDN:

  • Lossy WebP files are 25 to 35% smaller than JPEG.
  • Lossless WebP files are about 26% smaller than PNG.
  • Lossy AVIF files are around 50% smaller than JPEG.

Your own images will vary, so treat these as a starting point. All major browsers support WebP and AVIF. AVIF has one drawback: it can't show a rough version while it downloads, so the image appears only when the whole file has arrived. JPEG XL is another option for large, high-resolution photos, but give it a fallback format too. Google Search indexes images in BMP, GIF, JPEG, PNG, WebP, SVG and AVIF, so switching to a modern format doesn't cost you image search.

Serve the size people actually see

Compression can't fix an image that's simply too big. A 4,000-pixel-wide photo shown in a 600-pixel column wastes most of its bytes, however well it's compressed. Resize first, then compress.

Because screens differ, give the browser a few sizes and let it pick one with srcset and sizes. To offer a modern format with a fallback, wrap the image in a picture element:

<picture>
  <source type="image/avif" srcset="team-800.avif 800w, team-1600.avif 1600w" sizes="(max-width: 800px) 100vw, 800px">
  <source type="image/webp" srcset="team-800.webp 800w, team-1600.webp 1600w" sizes="(max-width: 800px) 100vw, 800px">
  <img src="team-800.jpg" alt="Our support team at the Berlin office" width="800" height="533">
</picture>

Always keep the <img> with a src: browsers and crawlers that don't understand the other options use it. Responsive images covers srcset and sizes in more detail.

A simple workflow

  1. Resize the image to the largest size it will be shown at, plus a larger copy for high-density screens if you need it.
  2. Pick the format from the table above.
  3. Lower the quality setting step by step and compare the result with the original at its real display size. Stop when you can see a difference. Tools such as Squoosh or ImageOptim make this side-by-side check easy.
  4. Publish with srcset and a fallback format, and set width and height so the page doesn't jump while images load.
  5. Lazy-load images further down the page, but not the main image at the top: delaying it slows the page down.
  6. Test the page in PageSpeed Insights. Its "Improve image delivery" check lists images that could be noticeably smaller (it ignores savings under 4 KiB).

On a site with many images, an image CDN or your CMS can do steps 1 to 4 automatically. Image compression is one kind of data compression; image SEO covers what else helps images show up in search.

Seonio

Put it to work on your own site

Keyword research, traffic, backlinks and clustering in one place. Start with a free $1 to test, no card required.