Use JPEG, WebP or AVIF for photographs, PNG or lossless WebP for screenshots and graphics that need exact pixels, and SVG for logos and icons. If you can only serve one raster format to modern browsers, WebP is the safest choice; AVIF is worth adding when you want the smallest photo files and can accept slower encoding.
The right answer depends on what the image contains and what the visitor's browser can decode. This guide focuses on that choice. For the broader workflow of resizing, compressing and lazy-loading, see our image optimization guide.
Lossy vs lossless: the decision underneath every format
A lossy format throws away detail the eye is unlikely to notice, such as fine colour variation in a sky. The file gets much smaller, but the discarded data is gone for good. A lossless format stores every pixel exactly, so decoding gives back what you put in, at the cost of larger files.
Photographs have smooth gradients and noisy texture, which lossy compression handles well. Screenshots, charts and text have hard edges and flat colour, where lossy compression produces visible smudging (ringing) around letters. That single difference explains most format advice.
The formats at a glance
| Format | Compression | Transparency | Animation | Best at |
|---|---|---|---|---|
| JPEG | Lossy | No | No | Photos with universal compatibility |
| PNG | Lossless | Yes (full alpha) | Rarely used (APNG) | Screenshots, UI, sharp graphics |
| WebP | Lossy or lossless | Yes | Yes | General-purpose replacement for JPEG and PNG |
| AVIF | Lossy or lossless | Yes | Yes | Photos where file size matters most |
| GIF | Lossless, 256 colours | 1-bit only | Yes | Legacy; usually better replaced |
| SVG | Vector (not pixels) | Yes | Via CSS or script | Logos, icons, simple illustrations |
JPEG
JPEG is the old workhorse. Every browser, email client, operating system and print service reads it. It has no alpha channel, so it cannot be transparent, and heavy compression produces blocky artefacts. It remains a sensible fallback for photos.
PNG
PNG is lossless with a full alpha channel, which makes it the default for screenshots, interface mockups and anything with text. Photographic content in PNG is usually far larger than the same picture in a lossy format, because PNG compression exploits repeated patterns that photos rarely contain.
WebP
WebP does both jobs: its lossy mode competes with JPEG and its lossless mode competes with PNG, and either can carry transparency. It can also store animation, which makes it a practical replacement for GIF. All current major browsers support it, so for many sites it is the simplest single upgrade.
AVIF
AVIF is based on the AV1 video codec. For photographs it tends to reach a given visual quality at smaller file sizes than WebP or JPEG, and it handles smooth gradients with less banding. The format also supports higher bit depths and wide-gamut or HDR colour, though how that displays depends on the browser, the screen and how the file was encoded, so do not assume it works end to end without checking. Browser support is broad but not identical to WebP; check a current compatibility table such as Can I Use before dropping fallbacks. The trade-off is that encoding is generally slower and more CPU-intensive, which matters if you process many images on upload.
SVG
SVG describes shapes with math instead of pixels, so it stays sharp at any size and is often tiny for simple art. It suits logos, icons and diagrams. It is a poor choice for photographs, and SVG files from untrusted sources should be sanitised because they can contain scripts.
Choosing by use case
| Use case | Recommended format |
|---|---|
| Photograph, hero image | AVIF with WebP and JPEG fallbacks |
| Photograph, single-format simplicity | WebP |
| Product photo with transparent background | WebP or AVIF (lossy with alpha); PNG if universal support is needed |
| Screenshot or UI capture | PNG or lossless WebP |
| Logo, icon, simple illustration | SVG |
| Short animation | Animated WebP or AVIF, or a muted looping video |
| Image for email or print | JPEG or PNG |
Serving modern formats safely with the picture element
The picture element lets the browser pick the first source it can decode. Order the sources from newest to oldest, and always finish with an img, which acts as the fallback and carries the alt text.
<picture>
<source srcset="hero.avif" type="image/avif">
<source srcset="hero.webp" type="image/webp">
<img src="hero.jpg" alt="Mountain lake at sunrise"
width="1600" height="900" loading="lazy">
</picture>
A browser that does not understand AVIF skips the first source, tries WebP, and falls back to the JPEG. The type attribute matters: it lets the browser skip a source without downloading it. Add srcset with w descriptors and sizes if you also serve several widths.
A worked example: one hero image, three files
Suppose you have a 1600 by 900 photograph. Export hero.jpg as the universal fallback, create hero.webp for the middle tier, and hero.avif for the best case. Open the page, check in your browser's network panel which file was actually requested, and compare the three file sizes. Sizes depend heavily on the photo and your quality setting, so judge the visual result at your real display size rather than trusting a number from another site. Our image converter can produce the alternate formats, and the image resizer helps you create the right dimensions first.
Common mistakes
- Using PNG for photographs. The file is often many times larger than necessary with no visible benefit.
- Re-saving a JPEG repeatedly. Each lossy save discards more data, and artefacts accumulate. Keep an original and export from it once.
- Converting a low-quality JPEG to PNG and expecting a fix. PNG preserves the damage perfectly; it cannot restore detail already lost. The file just gets bigger.
- Using lossy compression on text and UI. Edges smear. Choose lossless for those.
- Omitting width and height. Without them the browser cannot reserve space, so the page shifts as images load, hurting layout stability.
- Dropping the fallback. Serving only AVIF can leave some visitors with a broken image.
Frequently Asked Questions
Is WebP better than JPEG?
For most web photos, WebP gives smaller files at similar visual quality and adds transparency and animation. JPEG still wins on compatibility outside browsers, such as email, print and older software.
Should I replace all my images with AVIF?
Not blindly. AVIF is excellent for photos, but encoding is slower and support, while broad, is not identical everywhere. Use picture with fallbacks.
Which format keeps transparency?
PNG, WebP, AVIF, GIF (1-bit only) and SVG. JPEG cannot store transparency; transparent areas become a solid colour on conversion.
Is SVG always better for logos?
Usually, because it scales cleanly and is small. If the logo contains photographic texture or complex effects, a raster format may be more practical.
Comments
Leave a Comment
No comments yet. Be the first to comment!