Performance and accessibility 4 min read Updated
Choosing an image format for the web
In short
Use JPEG for photographs, PNG for transparency and exact detail, SVG for icons and diagrams, and WebP or AVIF with a fallback where they help.
An image has to be sharp, small and displayable in the browsers your visitors use. Those three demands often conflict. Choose the format for each image separately, not for the whole site.
Six formats, each suited to something different
The table summarises the MDN guide to image file types and formats and the web.dev advice on choosing an image format. MDN lists JPEG, PNG, GIF and SVG as supported in all versions of Chrome, Edge, Firefox, Opera and Safari, so the choice between them depends on the image.
| Format | Best suited for | Main limit |
|---|---|---|
| JPEG | Photographs and images with smooth tonal changes | Lossy; no transparency; sharp diagrams and text can look poor |
| PNG | Screenshots, diagrams, line art and images with transparency | Much larger files for photographs |
| GIF | Simple images and basic animation | Up to 256 colours; transparency is either on or off |
| SVG | Icons, logos and diagrams that must scale | Not suited to photographs; markup can grow very large |
| WebP | General images and animations, lossy or lossless | Historical browser support is not as deep |
| AVIF | Images and animations that need high compression | No progressive rendering; support is not yet comprehensive |
Use JPEG for photographs and PNG for detail
JPEG is a lossy format and remains the most popular choice for still photographs. The web.dev guide suggests trying several quality levels to find the balance between quality and file size. Lossy compression can make sharp diagrams and charts look poor, so keep those out of JPEG. JPEG also has no transparency.
PNG is lossless and supports full alpha transparency. Use it when an image must reproduce exactly or when it needs transparent areas. PNG files are much larger than most other formats, so use PNG for photographs only when the detail really matters.
Icons, diagrams and animation
SVG is a vector format written as XML. It stays sharp at any size, which suits icons, logos and diagrams that must be drawn accurately at different sizes. It is not a good fit for photographs, where the markup can become very large. Because SVG is text, compress it as described in the article on text compression.
GIF stores up to 256 colours and can animate, but for still images MDN prefers PNG. For animation, web.dev suggests a video element instead of GIF or APNG, because those formats produce much larger files than video of comparable quality. Loading only the images a visitor needs is covered in the article on lazy loading.
Working on something similar in your own product? A few honest sentences are enough – we read every enquiry and reply by email. Apply with your idea
WebP and AVIF: smaller files with caveats
WebP supports lossy and lossless compression, transparency and animation. MDN reports that lossy WebP files are on average 25–34% smaller than JPEG, and that lossless WebP files are typically 26% smaller than PNG. WebP now has broad support in current browsers, but it does not have deep historical support, so check the browsers your audience uses.
AVIF can make files smaller still. MDN puts lossy AVIF at around 50% smaller than JPEG, and notes that it compresses slightly better than WebP but is less widely supported. AVIF does not support progressive rendering, so the whole file must download before it can be shown. Because support is not yet comprehensive, provide a fallback whenever you use it.
The picture element provides the fallback
MDN recommends the picture element for formats with limited support. It lists source elements in order of preference, each with a type attribute, and ends with an img element that supplies the fallback, the dimensions and the alternative text. The MDN example offers an SVG, then a WebP, then a PNG, with a GIF in the img element as the last fallback, and it sets width and height on the img element.
Web.dev puts the same idea more simply: pair WebP or AVIF with a JPEG or PNG fallback.
Work through these steps for each image
- For a photograph, use JPEG, or WebP or AVIF with a JPEG fallback.
- If the image needs transparency or exact reproduction, use PNG, or WebP or AVIF with a PNG fallback.
- For an icon, logo or diagram, use SVG, which stays sharp at any size.
- For an animation, use a video element in place of GIF or APNG where possible.
- Test several quality levels, compare the file sizes and check that edges and text still look right.
This guide summarises the MDN image format guide and the web.dev advice on choosing an image format. The size percentages are the averages MDN reports for typical images, so measure your own files before you decide.
Common questions
- Which format should I use for photographs?
- JPEG is the usual choice for still photographs. WebP or AVIF can give smaller files, provided you include a JPEG or PNG fallback for browsers that cannot read them.
- Can I use SVG for photographs?
- No. SVG suits icons, logos and diagrams. Complex scenes such as photographs need raster formats, because SVG markup can become too large.
- Is GIF still worth using?
- For animation, web.dev suggests a video element instead of GIF, since GIF is limited to 256 colours and produces much larger files. For still images, PNG is the better choice.
Sources
- Image file type and format guide, MDN Web Docs. Accessed 24 November 2026
- Choose the right image format, web.dev. Accessed 24 November 2026
Further reading
-
Preload, preconnect and fetch priority
Use preconnect for the few most critical third-party origins, preload only what a page needs very soon, and set fetchpriority on the main image.
-
Where lazy loading helps and where it hurts
Use lazy loading for images and iframes below the first screen, and never for the element that shows first.
-
Text compression with Brotli and gzip
Serve HTML, CSS, JavaScript and SVG compressed with Brotli or gzip, and check the Content-Encoding header on real responses.
Have an idea that should exist? Or a working product that needs more customers, a new website or a complete rework? Bring us anything. Apply with your idea