Image Compression for the Web: A Performance Complete Guide
Everything about web image optimization — JPEG vs PNG vs WebP, lossy vs lossless compression, quality settings, Core Web Vitals impact, and modern image formats.
December 28, 2024
Images account for 50-70% of the bytes transferred on the average web page. They are the single biggest contributor to slow page loads — and slow pages cost real money. A 1-second delay in page load time reduces conversions by approximately 7%, according to data from Akamai. Google uses page speed as a ranking factor. Yet image compression remains one of the most neglected aspects of web development. This guide covers everything you need to know.
Why Image Compression Matters
A typical uncompressed photograph from a modern smartphone is 3-8MB. The same image, properly optimized for web use, can be 100-300KB — a 90%+ reduction — with no perceptible quality difference to users. Multiply this across every image on your site and the performance improvement is dramatic.
Google's Core Web Vitals — the set of performance metrics used in search rankings — are directly impacted by image optimization:
- Largest Contentful Paint (LCP) — Often the hero image or a product photo. Unoptimized images are the most common cause of poor LCP scores.
- Cumulative Layout Shift (CLS) — Images without explicit dimensions cause layout shifts as they load. Always specify width and height attributes.
Lossy vs. Lossless Compression
There are two fundamental types of image compression:
Lossy Compression
Lossy compression permanently removes image data that is unlikely to be noticed. JPEG is the classic lossy format — it discards fine color detail in a way that the human visual system is poor at detecting. At quality settings of 70-85%, JPEG images are typically indistinguishable from the original at normal viewing sizes, but are 3-10× smaller.
Lossy compression is ideal for: photographs, product images, background images, and any content where slight quality reduction is acceptable. Not suitable for: text screenshots, logos with flat colors, medical imaging, or any image where pixel-perfect accuracy matters.
Lossless Compression
Lossless compression reduces file size without discarding any data — the decompressed image is bit-for-bit identical to the original. PNG uses lossless compression (LZW algorithm). Lossless compression typically achieves 20-50% reduction, versus 60-90% for lossy.
Lossless compression is ideal for: UI elements, icons, logos, screenshots, graphics with flat colors and sharp edges, and any image where quality must be preserved exactly.
Image Format Comparison
JPEG
The most widely used format for photographs. JPEG uses lossy compression and does not support transparency. Quality settings typically range from 1-100, with 70-85 being the practical sweet spot for web images — significantly smaller than the original with imperceptible quality loss.
Use JPEG for: photographs, product images, background images, and any image with complex color gradients where transparency is not needed.
PNG
PNG uses lossless compression and supports transparency (alpha channel). PNG is significantly larger than JPEG for photographs but is the correct choice when pixel-perfect quality or transparency is required.
Use PNG for: logos, icons, UI elements, screenshots, graphics with text, and any image requiring transparency.
WebP
WebP is a modern format developed by Google that supports both lossy and lossless compression, as well as transparency and animation. At equivalent visual quality, WebP produces files 25-35% smaller than JPEG and 25-35% smaller than PNG.
Browser support: Chrome, Firefox, Safari (since 14), and Edge all support WebP. Internet Explorer does not. For most modern web applications, WebP is the best choice for both photographs and graphics — serve JPEG/PNG as fallback for older browsers if needed.
AVIF
AVIF is an even newer format based on the AV1 video codec. It produces smaller files than WebP at equivalent quality and supports HDR. Browser support is growing (Chrome 85+, Firefox 93+) but is not yet universal. Worth using with a WebP or JPEG fallback.
SVG
SVG is a vector format — not a bitmap format. It scales infinitely without quality loss and is often the smallest option for simple graphics. Use SVG for: logos, icons, simple illustrations, and any graphic that needs to scale to any size.
Choosing the Right Compression Quality
For JPEG and WebP, the quality setting controls the compression trade-off:
- 90-100% — Near-lossless. Little file size benefit. Use for print or archival.
- 80-90% — Excellent quality, moderate file size. Good for photography portfolios, high-end product images.
- 70-80% — Very good quality, significant file size reduction. Ideal for most web images.
- 60-70% — Good quality for normal content, noticeable artifacts in high-frequency areas (fine hair, grass, fabric).
- Below 60% — Artifacts become obvious. Only appropriate for very small thumbnails.
Always compare the compressed image against the original at 100% zoom before publishing. Compression artifacts are most visible in: fine textures, sharp edges, text in images, and areas with subtle color gradients (sky, skin tones).
Resizing for the Web
Serving an image larger than it will be displayed is a common performance mistake. A 4000×3000px image displayed at 800×600px transfers 25× more pixels than needed.
Guidelines for image dimensions:
- Hero images: match the maximum display width (usually 1200-1920px wide)
- Blog post content images: 800-1200px wide
- Thumbnails and cards: 400-600px wide
- Avatar/profile images: 100-200px
For responsive designs, use the srcset attribute to serve different image sizes for different screen resolutions. Modern frameworks (Next.js, Nuxt, Gatsby) handle this automatically.
Summary
Image compression is one of the highest-return performance optimizations available. Use WebP for most web images, with JPEG or PNG fallback. Apply quality settings of 70-85% for photographs. Resize images to match their display dimensions. The combination of format selection, quality optimization, and correct sizing typically reduces image payload by 60-90%, dramatically improving page load speed, Core Web Vitals scores, and user experience.