Sub topic 11
Choosing a format for each image
This chapter assumes you know the difference between raster and vector images, and between lossy and lossless compression. It also assumes you have met each format (JPEG, PNG, SVG, GIF, WebP, AVIF) in the earlier chapters. Here you will turn that knowledge into a repeatable decision for every image in a design.
The decision in one pass
Ask four questions in order. The first question that gives a clear answer usually settles the format.
- Is the image built from shapes, lines, and flat fills, such as an icon, logo, or simple illustration? If so, use SVG.
- Is it a photograph, or an image with soft gradients and fine texture? If so, use a lossy format: AVIF, WebP, or JPEG.
- Is it a screenshot, a UI mockup, or an image with text and hard edges that must stay exact? If so, use a lossless format: PNG or lossless WebP.
- Does it need transparency or motion? This narrows the choice further, as covered below.
Comparing the formats
| Format | Compression | Transparency | Animation | Best for |
|---|---|---|---|---|
| JPEG | Lossy | No | No | Photos when you need the widest compatibility |
| PNG | Lossless | Full alpha | No (APNG is rare) | Screenshots, sharp UI, images with text |
| SVG | Vector, not pixels | Yes | Possible with CSS or script | Icons, logos, simple illustrations |
| GIF | Lossless, 256 colors | On or off only | Yes | Almost nothing new |
| WebP | Lossy or lossless | Full alpha | Yes | General replacement for JPEG and PNG |
| AVIF | Lossy or lossless | Full alpha | Yes | Photos where file size matters most |
Two points in this table cause most mistakes. WebP and AVIF each cover both lossy and lossless modes, so "which format" and "which mode" are separate choices. GIF's transparency has no partial values, so soft edges and shadows turn into jagged halos.
Photographs
Photos have millions of slightly different colors. Lossless formats store all of that detail, so a PNG photo is often three to ten times larger than a JPEG of the same picture with no visible gain.
- AVIF usually gives the smallest file at a given look. It encodes slowly and can smooth fine grain or flatten subtle gradients, such as a sky, into visible bands.
- WebP is typically smaller than JPEG, encodes quickly, and is supported in current versions of all major browsers.
- JPEG is the safe fallback that every browser and every tool understands.
For a hero photo, a common approach is to export AVIF and WebP and keep a JPEG fallback. The picture element lets the browser choose the first format it supports.
<picture>
<source type="image/avif" srcset="hero.avif">
<source type="image/webp" srcset="hero.webp">
<img src="hero.jpg" width="800" height="450" alt="Team working at a shared desk">
</picture>Screenshots, UI, and text
Lossy compression adds faint noise around sharp edges. On a photo you cannot see it. Around letters and thin lines it looks like smudging. For product screenshots and anything with readable text, use PNG, or lossless WebP if file size matters. If a screenshot contains a photo, such as a feed with images, try lossy WebP at a high quality. Compare it with the PNG before you commit.
If the image has fewer than about 256 distinct colors, a palette PNG (PNG-8) can be far smaller than the default 24-bit PNG. Most export tools offer this as a color-count option.
Icons, logos, and illustrations
Use SVG when the artwork is made of paths. It stays sharp at any size, usually weighs a few kilobytes, and can take its color from the surrounding text.
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" role="img" aria-label="Add">
<path d="M12 5v14M5 12h14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>SVG is the wrong choice for a photo. Auto-traced photos produce huge files that look like posterized paintings. Also check that text in a logo is converted to outlines. Otherwise it renders in a fallback font on any machine that lacks yours.
Transparency and animation
For transparency, choose from PNG, WebP, AVIF, or SVG. Do not use JPEG, which cannot store it and will fill the area with a solid color, usually white or black. Avoid GIF unless the edges are fully hard.
For animation, a GIF is large and limited to 256 colors per frame. A short looping clip is almost always smaller as an MP4 or WebM video played with autoplay, loop, and muted attributes. Animated WebP or AVIF suits very short loops that must behave like an image. Animated SVG fits simple interface motion built from shapes.
Common errors
- PNG for every photo. The file is large and looks no better. Switch to a lossy format.
- JPEG for a logo or screenshot. You get ringing artifacts around edges and no transparency. Use SVG or PNG.
- Exporting a flat icon as a 2x PNG when SVG exists. You get two files instead of one resolution-independent file.
- AVIF with no fallback. An older browser shows a broken image. Always end a
pictureelement with a regularimg. - Choosing by habit. Compare file sizes and look at the result at 100% zoom. Chapter 13 covers how to set quality.
A worked example
Take a landing page with five assets.
- The logo is a set of paths, so it is an SVG.
- The hero is a photo, so it is AVIF and WebP with a JPEG fallback.
- The pricing-table screenshot has small text, so it is PNG, or lossless WebP if it is large.
- The feature icons are simple shapes, so they are SVG with
currentColor. - The five-second product demo loop is an MP4 with a WebM alternative, not a GIF.
Each choice follows from what the image contains, not from which format is newest.
Exercise
A designer exports a 1600 px wide photo with a soft sunset gradient as PNG and finds it is 2.8 MB. Name a better format choice, give one reason, and describe what to check about the new file.
Show answer
Use a lossy format, preferably WebP or AVIF with a JPEG fallback in a picture element, because photos contain too much varied detail for lossless compression to shrink well. Check the sky at 100% zoom for banding, because lossy encoders (AVIF especially) can flatten subtle gradients. If banding appears, raise the quality or switch to WebP or JPEG. Also compare the file sizes to confirm the saving.
Exercise
A marketing page needs a three-second looping product animation with a transparent background. List two format options and one drawback of each.
Show answer
Animated WebP supports transparency and animation, but the files can grow quickly for long or detailed clips. A video such as WebM (VP9) can also carry transparency in some browsers and is usually much smaller, but alpha support is not universal, so you may need a fallback. Animated GIF is also possible, but its 1-bit transparency leaves jagged edges and the file is large.