PNG, JPG, WebP or GIF: choosing the right image format for the web
Which format to use for photos, logos, screenshots and animations, and how much lighter WebP can make your pages.
Images are usually the heaviest part of a web page. Choosing the right format for each one is the easiest way to make a site faster, and it costs no quality you'd notice.
The short version
| Use | Best format | Fallback |
|---|---|---|
| Photos | WebP or AVIF | JPG |
| Logos and icons | SVG | PNG |
| Screenshots, diagrams and flat graphics | WebP (lossless) | PNG |
| Images with transparency | WebP | PNG |
| Short animations | A muted video loop, or animated WebP | GIF |
JPG: photos
JPG (or JPEG) uses lossy compression: it throws away detail your eye is unlikely to miss. That makes it good for photos and poor for sharp edges, text and flat colour, where it leaves smudgy artefacts. It has no transparency. A quality setting of about 75 to 85 usually looks the same as the original at a fraction of the size.
PNG: graphics and transparency
PNG is lossless: every pixel is kept exactly. That makes it right for screenshots, interface graphics and anything with text in it, and it supports full transparency. The cost is size. A photo saved as PNG can be five to ten times larger than the same photo as a JPG.
WebP: the default for most images
WebP does both jobs: lossy compression for photos and lossless compression for graphics, with transparency and animation in either mode. Google's own comparisons found lossy WebP files 25 to 34% smaller than JPGs of the same quality, and lossless WebP about a quarter smaller than PNG. Every current browser supports it, so on most sites WebP can simply replace JPG and PNG.
AVIF: smaller still
AVIF usually compresses even better than WebP, especially for photos, and all major browsers now support it. It's slower to encode, and some editing tools and content systems still don't handle it, so it's often served alongside WebP rather than instead of it.
GIF: only for compatibility
GIF is limited to 256 colours per frame, so photos look banded, and animated GIFs are very large. For animation on a website, a short muted video loop or an animated WebP is many times smaller. GIF still makes sense where nothing else is accepted, such as some email clients and messaging apps.
SVG: logos and icons
SVG isn't a grid of pixels but a description of shapes. It stays sharp at any size, is usually tiny for logos and icons, and can be styled with CSS. It's the wrong choice for photos.
Serving modern formats safely
The HTML picture element lets each browser pick the best format it supports:
<picture>
<source srcset="team.avif" type="image/avif">
<source srcset="team.webp" type="image/webp">
<img src="team.jpg" alt="The team at work" width="1200" height="800" loading="lazy">
</picture>
The width and height stop the page jumping while the image loads, and loading="lazy" waits to download images until they're about to scroll into view.
Convert and compress
Size matters as much as format. Export each image at the size it's displayed (a 4000-pixel photo shown 800 pixels wide wastes most of its bytes), then compress it.
- Convert existing files with PNG to WEBP or JPG to WEBP.
- Shrink files with the Image optimizer, which can resize them too.
- Turn screenshots that don't need transparency into smaller files with PNG to JPG.
All of these run in your browser, so your images aren't uploaded anywhere.
Try it
More posts
What a DNS lookup tells you about a domain
A, MX, TXT, CNAME and the other DNS records explained: what each one does, and what to check when a website or email stops working.
Read post →
How to check an SSL certificate, and what the details mean
Issuer, validity, covered names and the chain: how to read a certificate, and the errors that make browsers show a warning.
Read post →
The meta tags that still matter for SEO
Title, description, canonical, robots and Open Graph: the handful of tags worth getting right, and the ones you can forget.
Read post →