Design glossaryImage compression is reducing an image's file size, losslessly or lossily, so pages load faster with little or no visible loss of quality.
Image compression shrinks the number of bytes needed to store a picture. Images are usually the heaviest part of a web page, so compressing them well is one of the most effective ways to make a site load faster, especially on phones and slow connections. Done carefully, visitors cannot see the difference; done carelessly, photos turn blotchy and logos go fuzzy.
Lossy and lossless
- Lossy compression throws away detail the eye is unlikely to notice. It gives the biggest savings and suits photographs. JPEG, lossy WebP, and AVIF work this way.
- Lossless compression stores the same pixels more efficiently, so nothing is lost. It suits logos, screenshots, and graphics with sharp edges and flat color. PNG, GIF, and lossless WebP work this way.
Choosing a format
| Format | Best for | Notes |
|---|---|---|
| JPEG | Photos | Supported everywhere; no transparency. |
| PNG | Logos, screenshots, transparency | Lossless, so large for photos. |
| WebP | Photos and graphics | Lossy or lossless, with transparency; usually smaller than JPEG or PNG at similar quality. |
| AVIF | Photos | Often smaller again than WebP; slower to encode. |
| SVG | Logos and icons | Vector text file; tiny and sharp at any size. |
Resize before you compress
The biggest saving usually comes from dimensions, not compression settings. A 4,000-pixel-wide photo displayed in an 800-pixel column wastes most of its bytes, however well it is compressed. Resize images to roughly the largest size they will be shown, allowing for high-density screens, and let responsive images (srcset) serve smaller copies to smaller screens.
Image compression in WordPress
WordPress already does part of the work:
- It creates several resized copies of every upload (the thumbnail sizes) and adds
srcsetso browsers pick a suitable one. - It saves those JPEG copies at a quality setting of 82 by default, which developers can change with the
wp_editor_set_qualityfilter. - Very large uploads are scaled down to a maximum of 2,560 pixels for use on the site, with the original kept. The
big_image_size_thresholdfilter changes this. - WebP and AVIF uploads work when the server's image library supports them.
For more, an image optimization plugin or a CDN with image optimization can compress uploads, convert them to WebP or AVIF, and serve the right format to each browser. We walk through the options in our guide to image compression for WordPress.
Why it matters
Smaller images lower page weight, use less of visitors' data, and often improve Largest Contentful Paint, because the largest element on many pages is an image. PageSpeed Insights flags images that could be smaller or served in a more efficient format.
Common mistakes
- Uploading photos straight from a camera or phone at full size.
- Saving photos as PNG, which can make them many times larger than a JPEG or WebP.
- Compressing the same JPEG over and over. Each lossy save loses a little more; keep an original and export from it.
- Pushing quality so low that faces, skin, and gradients show blocky artifacts.
- Expecting server compression (gzip or Brotli) to shrink JPEG, PNG, or WebP files. They are already compressed; gzip and Brotli help text files such as HTML, CSS, JavaScript, and SVG.