Images and media

Choose an image format

Choose between JPEG, PNG, WebP, AVIF, SVG, and video based on the kind of image, transparency, animation, and file size.

8 minute lesson

~~~

The browser can display several image formats. The HTML stays the same:

<img src="harbor.webp" alt="Boats in Copenhagen harbor">

The format affects file size, quality, and what the image can contain.

Use this as a starting point:

ContentStart withWhy
A photoWebP, AVIF, or JPEGGood compression for detailed images
A screenshotPNG or WebPKeeps text and sharp edges clear
An image with transparencyPNG or WebPSupports transparent pixels
A logo or diagramSVGScales without becoming blurry
A long animationVideoBetter controls and compression than GIF

JPEG is still useful for photographs. It does not support transparency.

PNG keeps exact pixel detail and supports transparency. Large photographs saved as PNG are usually much heavier than they need to be.

WebP and AVIF can create smaller files at similar visual quality. Your image editor or build tool can generate them.

SVG is a vector format. The browser draws shapes from instructions instead of displaying a fixed grid of pixels. It works well for logos, icons, and diagrams.

<img src="route-map.svg" alt="Cycle route through the city center">

SVG is not a good format for a normal photograph.

Compare the result

Export one photo as JPEG, WebP, and AVIF. Open each file at the size it will appear on the page.

Compare two things:

  • can you see a meaningful quality difference?
  • how large is each file?

Choose the smallest version that still looks good. A fashionable format is not useful if your export looks worse.

Lesson completed