SVG vs PNG and JPEG: choosing an image format
When to use SVG, PNG or JPEG: vector versus raster, lossy versus lossless, transparency, and a simple decision guide with live examples.
Choosing between SVG, PNG and JPEG comes down to what the image contains. The formats store information in different ways, and each is good at one kind of picture and bad at another.
The core difference
PNG and JPEG are raster formats. They store a fixed grid of pixels. Enlarge them past their native size and the browser has to invent pixels, so edges turn soft. SVG is a vector format. It stores drawing instructions as text, and the browser draws them at the size you ask for.
MDN’s image guide summarizes the intended uses this way:
- SVG for icons, UI elements and diagrams, and anything that must render accurately at any size.
- PNG for screenshots, diagrams, logos and line art that need precise reproduction, and for images that need transparency.
- JPEG for photographs and other continuous-tone images.
The same guide describes PNG as lossless with full alpha transparency, and JPEG as lossy with no alpha channel. Lossy compression discards detail to save bytes. That is fine in a photograph, where fine variation hides the loss. MDN warns that applying lossy compression to content that needs sharpness, such as diagrams or charts, can give unsatisfactory results. Text and hard edges are where JPEG artifacts show up first.
Scaling: where SVG wins
The practical advantage is that one SVG file works at every size and pixel density. You do not export a 1x and a 2x version, and you do not worry about how the graphic will look on a high-density screen.
The two badges below use the same shapes. The second is drawn through scale(2.75), yet its edges and checkmark stay crisp. Change the scale factor to something much larger and the edges still stay sharp.
A bitmap of the same badge would need to be exported at the largest size you plan to use, or it would look soft when enlarged.
Transparency and styling
PNG supports full alpha transparency, so it is the standard fallback when you need a see-through background in a raster image. SVG handles transparency naturally because unpainted areas are simply empty. SVG also takes opacity, gradients and blend settings as attributes or CSS.
When an SVG is inlined into the page, its colors can be controlled by page CSS. For example, an icon that uses fill="currentColor" takes on the text color of its parent, which makes dark mode and hover states cheap. When the same file is loaded with <img>, page CSS cannot reach inside it, and MDN lists further restrictions for that mode: scripts do not run and external resources are not loaded. See what is SVG for the three embedding methods.
Here an icon uses currentColor. Change the color on the <g> and the shape follows.
Where SVG loses
Photographs. MDN states that SVG is not suited to photographs or bitmap-style images. You can embed a bitmap inside an SVG, but that gives you the raster file plus wrapper overhead, with none of the vector benefits. For photos, use JPEG, or WebP or AVIF where you can serve them. MDN recommends preferring those two for raster images because they generally compress better than PNG, JPEG and GIF.
Very complex artwork. A detailed illustration can contain a large number of path segments. File size and rendering cost grow with the amount of geometry. If an SVG export is larger than a compressed bitmap of the same picture, the bitmap may be the practical choice. Test both. The optimization guide covers reducing SVG size.
Pixel-exact reproduction. A screenshot of an interface is a record of pixels, not shapes. Use PNG, which MDN names as the right choice for screenshots where lossy artifacts would be very visible.
Effects that depend on pixel data. Textures, grain, painterly gradients and photographic noise are better stored as pixels.
A quick decision guide
- Is it a photograph or continuous-tone image? Use JPEG, or WebP or AVIF if you can serve them.
- Is it a screenshot or pixel-exact capture? Use PNG.
- Is it an icon, logo, chart, diagram or simple illustration, especially one that appears at several sizes? Use SVG.
- Does it need to change color, respond to hover or animate? Use inline SVG.
- Must the logo also work somewhere that does not render SVG, such as an email client or a social sharing card? Check what that destination accepts, and keep a PNG export alongside the SVG if it does not. See browser compatibility.
Offering fallbacks
MDN shows a <picture> element that lists formats in order of preference. The browser uses the first <source> whose type it supports:
<picture>
<source srcset="diagram.svg" type="image/svg+xml" />
<source srcset="diagram.webp" type="image/webp" />
<source srcset="diagram.png" type="image/png" />
<img src="diagram.gif" width="620" height="540"
alt="Diagram showing the data channels" />
</picture>
Always give the <img> a meaningful alt and explicit dimensions so the layout does not shift while it loads.
Mixing formats
Real pages use more than one. A common pattern is a JPEG or WebP hero photo, SVG icons and logo, and a PNG for any screenshot. The formats are tools for different jobs, so the goal is to match each image to the right one rather than pick a single winner.
If you have decided SVG fits, the next step is to understand how it scales inside a layout. Read the viewBox guide and responsive SVG.
Sources
Checked against these references on 2026-11-21.