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 the main formats: JPEG, PNG, SVG, GIF, WebP and AVIF. Here you will turn that knowledge into a repeatable decision.
Ask three questions
Answer these in order for every image.
- Is the image made of shapes (an icon, a logo, a simple illustration)? If yes, export SVG.
- Is it a photograph or an image with smooth gradients and many colors? If yes, use a lossy format.
- Does it have sharp edges, flat color, text, or transparency? If yes, use a lossless format, or a modern format in lossless mode.
Format comparison
| Format | Best for | Transparency | Animation | Main caution |
|---|---|---|---|---|
| SVG | Icons, logos, simple illustrations | Yes | Possible with CSS | Large file if the drawing is complex |
| JPEG | Photographs | No | No | Artifacts around sharp edges and text |
| PNG | Screenshots, flat graphics, sharp edges | Yes | Rare | Large file for photographs |
| WebP | Almost anything raster | Yes | Yes | Needs a fallback only for very old browsers |
| AVIF | Photographs at the smallest size | Yes | Yes | Slow to encode, and can look soft at low quality |
| GIF | Almost nothing | One-bit only | Yes | Only 256 colors, and large files |
Common cases
- Hero photograph: AVIF or WebP, with a JPEG fallback.
- Logo: SVG. If you must use a raster file, use PNG.
- Interface screenshot: PNG or lossless WebP. JPEG blurs small text.
- Photo with a transparent background: WebP or AVIF. A PNG would be very large.
- Short animation: an animated WebP, or a video file. Avoid GIF.
Serve a fallback
Newer formats save bytes, but a few browsers cannot read them. The picture element lets the browser take the first format it supports and fall back to JPEG.
<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>Common mistakes
- Saving a photograph as PNG. The file can be five to ten times larger than a JPEG.
- Saving text or a screenshot as a low-quality JPEG. Edges look smudged.
- Exporting a flat logo as a raster file when an SVG would stay sharp at every size.
- Using GIF for animation when WebP or video is smaller.
Exercise
A page needs three images: a company logo made of two flat shapes, a full-width photo of a street, and a screenshot of a settings panel with small text. Name a format for each and give one reason.
Show answer
Logo: SVG, because it is built from shapes and stays sharp at any size. Street photo: AVIF or WebP with a JPEG fallback, because lossy compression suits photographs and gives small files. Settings screenshot: PNG or lossless WebP, because lossless compression keeps small text and sharp edges clean.