Images are usually the heaviest part of a web page, so choosing the right format makes a big difference to how quickly your site loads and how good it looks. Pick the wrong one, and you can end up with blurry logos, huge photos, or graphics that look jagged on high-resolution screens. In this guide we'll look at each of the main formats, what it's good at, and how to use the best one for every image.
The key ideas
A few terms come up again and again when comparing formats.
Raster or vector
- Raster images (JPEG, PNG, WebP, AVIF and GIF) are grids of coloured dots called pixels. They're perfect for photos, but get blurry or blocky if you enlarge them beyond their original size.
- Vector images (SVG) are instructions for drawing shapes, like "a blue circle here, a line there". They stay perfectly sharp at any size, which makes them ideal for logos and icons.
Lossy or lossless compression
- Lossy compression makes files much smaller by throwing away detail that's hard to notice. Push it too far, and you'll see smudges and blocks (called artefacts).
- Lossless compression keeps every pixel exactly as it was, so files are larger, but there's no loss in quality.
Transparency and animation
Some formats support transparency (also called an alpha channel), so an image can sit on any background, like a logo with no white box around it. Some also support animation.
Formats at a glance
| Format | Type | Compression | Transparency | Animation | Best for |
|---|---|---|---|---|---|
| JPEG | Raster | Lossy | No | No | Photos, as a fallback |
| PNG | Raster | Lossless | Yes | Yes (APNG) | Screenshots, graphics with sharp edges |
| WebP | Raster | Both | Yes | Yes | Almost everything |
| AVIF | Raster | Both | Yes | Yes | Photos, at the smallest file sizes |
| SVG | Vector | Text, can be compressed by the server | Yes | Yes (with CSS) | Logos, icons, illustrations, charts |
| GIF | Raster | Lossless, 256 colours | On or off only | Yes | Rarely the best choice today |
Every format in this table works in all current major browsers.
JPEG
JPEG (also written JPG) has been the standard format for photos on the web for decades. Its lossy compression is excellent at shrinking images with smooth gradients and millions of colours.
- Pros: works absolutely everywhere, handles photos well, and lets you choose a quality level to balance size and detail.
- Cons: no transparency, and it smudges sharp edges and text. Each time you edit and re-save a JPEG, it loses a little more quality, so keep your originals in a lossless format.
Use it for: photos, especially as the fallback version alongside WebP or AVIF.
PNG
PNG uses lossless compression and supports full transparency, including partly see-through areas such as soft shadows.
- Pros: pixel-perfect quality, crisp text and edges, and full transparency.
- Cons: photos saved as PNG are often several times larger than the same photo as a JPEG, with no visible benefit.
Use it for: screenshots, diagrams and graphics with text or sharp edges, when SVG isn't an option. For transparent images, lossless WebP usually gives the same result in a smaller file.
Good to know: the original version of this post said animated PNG (APNG) isn't widely supported. It now works in all major browsers.
WebP and AVIF: the modern formats
WebP and AVIF do everything JPEG, PNG and GIF can do (lossy and lossless compression, transparency and animation) in much smaller files.
WebP
- Google's figures show lossy WebP images around 25–34% smaller than JPEGs of similar quality, and lossless WebP around 26% smaller than PNGs.
- It's fast to encode and decode, and it's supported by almost every image editor and content management system.
- It has worked in all major browsers since 2020, when Safari added support.
AVIF
- AVIF usually compresses even better than WebP, especially for photos, and handles smooth gradients well, without the banding (visible stripes) other formats can show.
- It also supports HDR (high dynamic range) and wide colour, for brighter, richer images on screens that can display them.
- Encoding is slower, so it takes longer to create AVIF files, though that only matters when you're saving them.
- It has worked in all major browsers since January 2024, when Edge added support.
Correction: the original version of this post said WebP wasn't yet universally supported and might need fallbacks. Every current major browser supports WebP, and AVIF too. Fallbacks are now only needed for very old browsers.
One to watch: JPEG XL. JPEG XL is another modern format, with excellent compression and the ability to convert existing JPEGs into smaller files without any loss in quality. Safari supports it (from version 17), and Chrome added support in version 155 in October 2026, but it isn't in every browser yet. If you'd like to use it, always offer a fallback with the <picture> element (see below).
SVG
SVG (Scalable Vector Graphics) describes images as shapes, written as code. Because the browser draws them fresh at whatever size is needed, they're perfectly sharp on every screen. Here's the same SVG icon at three sizes, recoloured with CSS:
The icon uses fill="currentColor", so it automatically takes on the CSS color of whatever it's placed in.
- Pros: sharp at any size, often tiny files for simple graphics, and when placed directly in your HTML, it can be styled and animated with CSS.
- Cons: unsuitable for photos, and very detailed illustrations can produce large files that are slow to draw.
Use it for: logos, icons, illustrations, charts and diagrams.
Accessibility and safety: an SVG used with <img> needs alt text like any other image. An SVG placed directly in your HTML can be labelled with role="img" and aria-label, or hidden with aria-hidden="true" if it's decorative. SVG files can also contain scripts, so never let visitors upload SVGs that are then shown directly on your site without first cleaning them up.
GIF, and better ways to animate
GIF dates from 1987. It's limited to 256 colours, and its transparency is all or nothing, with no soft edges. It's still famous for short looping animations, but it's now almost never the best choice:
- For still images, PNG, WebP or SVG are better in every way. The original version of this post recommended GIF for simple graphics with few colours; PNG or SVG will look as good or better, in a similar or smaller file.
- For animations, animated WebP and AVIF are much smaller. Better still, a short video is often a fraction of the size of the same animation as a GIF.
Here's how to use a video as a "GIF" that plays silently and loops:
<video autoplay muted loop playsinline width="480" height="270">
<source src="animation.webm" type="video/webm">
<source src="animation.mp4" type="video/mp4">
</video>
mutedis required for browsers to allow automatic playback.playsinlinestops iPhones from opening the video full screen.- Animations that play automatically for more than five seconds should have a way to pause them. Adding the
controlsattribute is the simplest option.
Choosing and serving the right format
Choose the kind of image you have for a quick recommendation:
Offer modern formats with a fallback
The <picture> element lets you list several formats. The browser uses the first one it supports, and falls back to the <img> otherwise:
<picture>
<source srcset="beach.avif" type="image/avif">
<source srcset="beach.webp" type="image/webp">
<img src="beach.jpg" alt="Waves rolling onto a sandy beach" width="1200" height="800">
</picture>
The alt text, width and height go on the <img>, and apply whichever source is used.
More tips
- Resize images to the size they're displayed at (or about twice that for high-resolution screens), rather than uploading huge originals. The
srcsetandsizesattributes let browsers pick the right size for each screen. - Compress sensibly. For lossy formats, a quality setting around 60–80 usually looks great at a fraction of the size. Compare a few settings by eye.
- Lazy-load images further down the page with
loading="lazy", but not the main image at the top. - Always include
alttext describing the image, oralt=""if it's purely decorative. - Let tools do the work. Image editors, content management systems and image services can create WebP and AVIF versions automatically.
Wrapping up
For most websites today, the answer is simple: use SVG for logos, icons and illustrations, and AVIF or WebP for photos and other images, with a JPEG or PNG fallback inside <picture> if you want to support very old browsers. Use video instead of GIF for animations, size and compress your images carefully, and your pages will look sharp and load quickly.