
Most image optimization advice starts and ends with compression. That's incomplete. A smaller file can still produce a slow page if the browser discovers it late, downloads the wrong dimensions, or lazily loads the image that defines the first screen.
The practical answer to how to optimize images for web has three parts: choose an efficient format, serve a size that matches the rendered slot, and give critical images the right loading priority. Compression matters, but delivery order often matters more for the image users notice first.
Image optimization covers far more than shrinking files. It also determines when browsers discover an asset, which dimensions they request, and whether that asset competes effectively for bandwidth. Images often make up the largest part of a page payload, and an image frequently becomes the largest contentful element in the initial viewport. Research summarized in an arXiv analysis connects these delivery choices with perceived speed and Core Web Vitals, especially Largest Contentful Paint.

A practical audit should ask:
Legacy formats still account for much of Internet image traffic, so conversion can produce worthwhile savings. It cannot, however, repair a hero image hidden behind lazy loading, discovered late in the document, or delivered at several times its display width. The request must also arrive in the right order. For an above-the-fold image, use accurate srcset and sizes, avoid lazy loading, and consider fetchpriority="high" when it defines LCP. Reserve that priority for the page's main visual, because raising too many requests can delay other work.
Format selection determines how efficiently pixels are encoded. WebP and AVIF can reduce payloads for suitable assets, while JPEG and PNG remain useful for compatibility, transparency, and particular graphic styles.
Responsive delivery determines how many pixels the browser downloads. A phone should not receive a desktop-sized hero because the original asset exists at that resolution. srcset, sizes, and picture let the browser choose a resource that fits the rendered slot.
Loading prioritization determines when the request competes for bandwidth. The image that establishes LCP needs different treatment from a product thumbnail far below the fold.
Practical rule: Fix the image's discovery and priority before chasing the last bytes. A moderately smaller hero that starts early can improve the experience more than an aggressively compressed file that starts late.
There isn't one universally superior web format. The right choice depends on whether the asset is photographic, transparent, geometric, animated, or central to the first viewport.
For photographs, JPEG remains a useful baseline because its quality and file-size trade-off is familiar and broadly compatible. A published encoding comparison uses JPEG quality 60 as a baseline, with WebP around 65 and AVIF around 50 for similar visual quality. In that comparison, AVIF files were about 36% smaller and WebP files about 15% smaller than the equivalent JPEG, as documented in the quality-setting comparison.
Don't copy the same numeric quality value across codecs. Quality scales aren't interchangeable. A setting that looks acceptable in JPEG can be too aggressive in AVIF or unnecessarily conservative in WebP.
| Image Type | Primary Format | Fallback | Quality Setting | Typical Savings vs JPEG |
|---|---|---|---|---|
| Photographic hero or product image | AVIF | WebP or JPEG | AVIF about 50 | About 36% smaller in the cited comparison |
| General photographic content | WebP | JPEG | WebP about 65 | About 15% smaller in the cited comparison |
| Legacy photographic asset | JPEG | None required | JPEG 60 baseline | Baseline |
| Transparent logo or sharp graphic | PNG or SVG | PNG | Test visually | Format-dependent |
| Simple illustration or icon | SVG | PNG | Not applicable | Avoids raster scaling waste |
| Animation | Animated WebP or GIF where required | GIF | Test visually | Depends on content |
The broader compression evidence supports the value of modern formats. Google's WebP study found WebP files were 25% to 34% smaller than equivalent JPEGs at the same SSIM quality level. The same research summarizes compression ratios reaching up to 3:1 for older lossless PNG and up to 20:1 for lossy JPEG and WebP, though actual results vary substantially by image content.
WebP is often the safer default when you want a practical balance of compression, tooling, and fallback support. AVIF can justify extra encoding and testing for photo-heavy pages where every byte matters, but a fallback-oriented implementation remains sensible. A large-scale study reported WebP on 16.6% of images and AVIF on 4.3%, with 40% of sites using WebP and 11% using AVIF, so universal AVIF-only delivery would still be an unreliable assumption according to the study.
For source-file preparation, a camera negative or design file shouldn't be uploaded directly as a web asset. Convert and resize it before delivery, using a workflow such as converting DNG to JPG when a broadly compatible photographic output is appropriate.
Responsive images solve a simple problem: the browser shouldn't download more pixels than the layout needs. A desktop monitor, tablet, and phone can all display the same content at different rendered widths, so one fixed src often serves the wrong resource.
Start with width variants:
<img
src="product-800.jpg"
srcset="
product-400.jpg 400w,
product-800.jpg 800w,
product-1200.jpg 1200w,
product-1600.jpg 1600w"
sizes="(max-width: 600px) 100vw, (max-width: 1100px) 80vw, 1200px"
width="1200"
height="800"
alt="Blue ceramic coffee mug on a wooden table">
The w descriptors tell the browser the intrinsic width of each file. The sizes attribute describes the image's expected layout width, so the browser can choose among those candidates using viewport size and device pixel density. Without accurate sizes, the browser may make a poor choice and download an unnecessarily large resource.
Use picture when you want to offer modern formats while retaining a dependable fallback:
<picture>
<source
type="image/avif"
srcset="
product-400.avif 400w,
product-800.avif 800w,
product-1200.avif 1200w"
sizes="(max-width: 600px) 100vw, 80vw">
<source
type="image/webp"
srcset="
product-400.webp 400w,
product-800.webp 800w,
product-1200.webp 1200w"
sizes="(max-width: 600px) 100vw, 80vw">
<img
src="product-800.jpg"
width="1200"
height="800"
alt="Blue ceramic coffee mug on a wooden table">
</picture>
The final img remains important. It supplies the fallback and carries the alt text, dimensions, and default behavior.
Resolution switching serves the same composition at different sizes. Art direction serves a different crop when the composition must change:
<picture>
<source
media="(max-width: 600px)"
srcset="portrait-mobile.avif"
type="image/avif">
<source
media="(max-width: 600px)"
srcset="portrait-mobile.webp"
type="image/webp">
<source
srcset="wide-desktop.avif"
type="image/avif">
<source
srcset="wide-desktop.webp"
type="image/webp">
<img
src="wide-desktop.jpg"
width="1600"
height="700"
alt="Designer presenting a dashboard to a small team">
</picture>
Always provide width and height, or reserve space with a reliable aspect ratio. The browser can then allocate the image's space before the file arrives, reducing the risk of Cumulative Layout Shift.
The most important image on a page isn't necessarily the largest file. It's the image users need to see first, usually the hero, featured product image, or editorial lead image that becomes the LCP element.
Start by confirming which element becomes LCP in a real page load. Chrome DevTools, Lighthouse, and PageSpeed Insights can identify the element and show whether the browser discovered it promptly. If the hero image is visible immediately, don't mark it loading="lazy".
<img
src="hero-1200.webp"
srcset="hero-800.webp 800w, hero-1200.webp 1200w, hero-1600.webp 1600w"
sizes="100vw"
width="1600"
height="900"
fetchpriority="high"
alt="Modern workspace with natural light">
fetchpriority="high" is a signal that tells the browser this image deserves earlier attention. It doesn't replace correct sizing or format selection, and it shouldn't be added to every image. Too many high-priority requests dilute the distinction the browser needs to make.

Use eager loading for the image that defines the initial viewport. Use lazy loading for content below that viewport, especially on long pages with galleries, article images, or product recommendations.
<img
loading="lazy"
src="related-400.webp"
width="400"
height="300"
alt="Related product in matte black">
The common failure is applying lazy loading through a theme or plugin to every image. That can delay the very resource that determines LCP. The opposite failure is loading an entire page eagerly, forcing below-the-fold assets to compete with HTML, CSS, fonts, and the critical image.
If the LCP image is a CSS background, the browser may discover it later than an image in the document. A preload hint can expose it earlier:
<link
rel="preload"
as="image"
href="/images/hero.webp"
fetchpriority="high">
Use preloading selectively. The resource must be critical, and its URL should match the image request the page will ultimately make. Otherwise, you can create duplicate downloads or consume bandwidth without improving the user's first view.
The right question isn't “Can this image be compressed further?” It's “Is the browser spending its early bandwidth on the image that matters?”
For an additional visual walkthrough, use this video on critical image prioritization.
Optimization without testing is mostly guesswork. A file can look small in a folder while the page still downloads the wrong candidate, discovers the LCP image late, or shifts the layout when the image appears.

Run the same page through a repeatable sequence:
Img, and check which format, dimensions, and file size the browser receives.Lighthouse flags an image as optimizable when its potential savings reach 4 KiB or greater, making that threshold useful for prioritizing work across pages with many small assets as described in this image optimization guidance. Don't treat every flagged image as equally valuable. A saving on the LCP image or a repeated template asset deserves more attention than an inconsequential image that's rarely requested.
A successful conversion should improve the rendered experience without creating a new problem. Check whether the LCP image starts early, whether the page reserves its dimensions, and whether lazy-loaded content remains deferred until it's useful.
Use the browser's throttling controls to test slower connections and constrained devices. Compare the waterfall before and after each meaningful change. If the image file is smaller but the request begins later, the page may not improve.
Also test format fallback behavior. Disable or bypass modern formats where possible, then confirm the JPEG or PNG fallback renders with the correct dimensions, alt text, and layout reservation. A modern format strategy that fails without any indication is worse than a slightly less efficient strategy that works consistently.
Keep a short deployment checklist:
srcset and sizes select sensible resources across viewports.A reliable workflow treats image delivery as a publishing decision, not a compression task performed after a page becomes slow.

Start with the largest practical source, then crop and resize it to the maximum dimensions the layout can display. Use Squoosh for browser-based visual comparisons, Sharp for automated Node.js pipelines, and ImageMagick for batch transformations. Keep originals outside the delivery directory, so later edits do not require recompressing an already degraded file.
Generate WebP for broad modern delivery, and add AVIF when its smaller output justifies another variant and fallback path. Keep JPEG or PNG when compatibility, transparency, or graphic sharpness matters. A PSD to PNG conversion workflow is useful when a design source needs a transparent raster output before web-specific variants are generated.
Create width variants and write accurate sizes values so the browser requests an appropriate resource. Use picture for format negotiation or art direction. Add explicit dimensions, or an equivalent aspect-ratio reservation, to prevent layout shifts.
Delivery order often matters more than another round of compression. Keep below-the-fold images lazy, but make the LCP image discoverable early, avoid lazy loading it, and use fetchpriority="high" only when it is the page's priority image. Confirm that srcset and sizes do not cause a large desktop asset to load on a narrow viewport.
After deployment, inspect representative templates in Lighthouse and DevTools. Compare waterfalls before and after meaningful changes, especially on slower connections and constrained devices. Store these checks with the build or content workflow so uploads, theme changes, or plugin settings do not reintroduce oversized assets or delay the LCP request.
Accessibility belongs in the same process. Use descriptive filenames where they help editors, write alt text that explains each image's purpose, and give decorative images empty alternative text instead of inserting keywords.
For a broader collection of free image, file, text, and developer utilities, Devnitys provides a curated directory with direct links and descriptions. Start with one high-traffic page, identify its LCP image, generate responsive variants, verify request priority, and then apply the workflow across the site.
Devnitys helps you find free online tools for image conversion, compression, file preparation, and related web tasks without downloads or signups. Use the directory when a publishing workflow needs a suitable utility, then validate the resulting page rather than judging the file size alone.