Sub topic 6
Choosing asset formats: SVG, PNG, JPEG, and WebP
This chapter assumes you can export from a design tool such as Figma, Sketch, or Adobe XD. It also assumes you know that a web page loads images through HTML <img> elements or CSS backgrounds. The goal is to pick the right file format for each asset and write that choice into the handoff, so the developer does not have to guess. The next chapter covers export scales and file names.
Why format is a handoff decision
A format changes how sharp an asset looks, how many kilobytes it adds to the page, and whether CSS can restyle it. If the handoff leaves the format open, developers usually take whatever the design tool exported by default. Common results are a 2 MB PNG of a photo, or a JPEG logo with gray fuzz around its edges.
Two ideas explain most of the choices:
- Vector or raster. A vector file stores shapes and paths, so it scales to any size without losing sharpness. A raster file stores a grid of pixels and has a fixed resolution.
- Lossy or lossless. A lossy format discards some detail to shrink the file. A lossless format keeps every pixel exactly.
The four formats
SVG
SVG (Scalable Vector Graphics) is a vector format written as text (XML). It suits logos, icons, simple illustrations, and diagrams. Its strengths are:
- It stays sharp on every screen density, so one file replaces several exports.
- Simple shapes are often only a few hundred bytes.
- When it is placed inline in the HTML, CSS can change its colors, which allows hover states and dark mode without extra files.
Its limits are:
- Files with thousands of paths, heavy blurs, or complex filters become large and slow to render.
- It is a poor fit for photographs.
- Colors cannot be restyled when the file is loaded through
<img src="logo.svg">or a CSSbackground-image. Only inline SVG can inherit page styles.
PNG
PNG is a lossless raster format with full transparency (an alpha channel). It suits screenshots, UI captures, images with sharp text or flat color areas, and raster assets that need a transparent background. It is a poor choice for photographs, because the lossless data makes the files very large.
JPEG
JPEG is a lossy raster format built for photographs. It handles smooth gradients and natural texture well, and it produces small files. It has no transparency. At low quality settings it produces blocky artifacts and halos around sharp edges and text, so it is a poor choice for logos and screenshots.
WebP
WebP is a newer raster format that can be lossy or lossless, supports transparency, and supports animation. At similar visual quality, a lossy WebP is commonly 25 to 35 percent smaller than a JPEG, and a lossless WebP is usually smaller than the equivalent PNG. All current major browsers support it. It is a good default delivery format for photos and raster illustrations.
Comparison
| Feature | SVG | PNG | JPEG | WebP |
|---|---|---|---|---|
| Type | Vector | Raster | Raster | Raster |
| Compression | Text, optional gzip | Lossless | Lossy | Lossy or lossless |
| Transparency | Yes | Yes | No | Yes |
| Animation | Yes (CSS or SMIL) | No | No | Yes |
| Best for | Icons, logos, flat art | Screenshots, sharp UI | Photos | Photos and raster art |
| Restylable with CSS | Yes, when inline | No | No | No |
| Scales without blur | Yes | No | No | No |
Choosing a format
Apply the path to typical assets:
- Company logo: SVG. Keep a PNG only for places that cannot render SVG, such as email clients or social sharing images.
- Navigation and action icons: SVG, drawn in one color so the developer can recolor them.
- Hero photograph: WebP with a JPEG fallback.
- Product screenshot with small text: PNG or lossless WebP.
- Textured or painterly illustration: WebP or PNG. An SVG of this art would be enormous.
- Flat illustration of a few shapes: SVG.
Preparing SVGs so they are usable
An SVG that looks right in the design tool can still be hard to use in code. Check these points before you hand it off:
- Convert text to outlines in logos so the shape does not depend on installed fonts. Leave text as live text only when the developer will render it as HTML.
- Remove hidden layers, unused masks, and clipped-off shapes. They still ship in the file.
- Do not embed raster images inside an SVG. A base64 PNG wrapped in SVG gains nothing and costs about a third more bytes.
- Draw icons on a consistent artboard, such as 24 by 24, with the same stroke width across the set. A consistent
viewBoxlets one CSS size rule fit every icon. - Use one color for single-color icons, so it can be swapped for
currentColor. Multi-color icons keep their own fills. - Run an optimizer such as SVGO to strip editor metadata, which often cuts file size by half.
This example shows the result for an inline icon. The stroke takes the button's text color, so hover and disabled states recolor it for free:
<button class="icon-button" type="button">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round"
aria-hidden="true">
<path d="M5 12h14M12 5l7 7-7 7"/>
</svg>
Next
</button>The aria-hidden="true" attribute marks the icon as decorative, because the visible text "Next" already names the control. If an icon stands alone with no text, it needs an accessible name instead. The accessibility chapter covers this.
Preparing raster assets
For photographs and raster illustrations, hand off the highest-quality source, and state the delivery format separately. A good rule is to keep the original lossless (a PNG or the design file itself) and let the build pipeline or the export step produce the WebP and JPEG versions. Compressing a JPEG again and again loses quality each time.
Quality settings matter more than the format name. These starting points work for most web photos:
- JPEG: quality 70 to 80. Below about 60, artifacts become visible on faces and skies.
- Lossy WebP: quality 75 to 80 gives results similar to JPEG at 80, with smaller files.
- PNG: reduce the palette to 256 colors (PNG-8) for flat graphics with few colors. Keep 24-bit PNG for gradients and soft shadows.
Check three things on each export:
- Dimensions. Do not ship a 4000-pixel photo for a 600-pixel slot. The next chapter explains how to choose widths.
- Transparency edges. A transparent PNG with soft shadows can show a halo on a colored background. Test it on the real background color.
- Color profile. Export in sRGB. Images in other color spaces can look washed out or oversaturated in browsers.
Fallbacks and delivery
WebP support is broad, but a fallback costs little and protects older environments. The <picture> element lets the browser take the first source it understands:
<picture>
<source type="image/webp" srcset="hero-800.webp 800w, hero-1600.webp 1600w"
sizes="(min-width: 960px) 50vw, 100vw">
<img src="hero-800.jpg"
srcset="hero-800.jpg 800w, hero-1600.jpg 1600w"
sizes="(min-width: 960px) 50vw, 100vw"
width="800" height="450"
alt="Team reviewing a design on a shared screen">
</picture>The width and height attributes let the browser reserve space before the image loads, which prevents the page from jumping. Your handoff should supply the intrinsic dimensions so the developer can fill them in.
Recording the decision in the handoff
Write the choice next to each asset, not only in the export settings. A short asset table is enough:
| Asset | Format | Reason | Fallback |
|---|---|---|---|
| Logo | SVG | Vector, single color | PNG for email |
| Nav icons | SVG, 24 px grid | Recolored with CSS | None |
| Hero photo | WebP, quality 80 | Photo, large | JPEG |
| App screenshot | PNG | Small sharp text | None |
Common mistakes
- Photos as PNG. A 1600-pixel photo can be several megabytes as PNG and a few hundred kilobytes as WebP.
- Logos as JPEG. The compression leaves noise around edges, and the white box shows on colored backgrounds.
- SVG for photographic art. Tracing a painting into thousands of paths creates a file larger than a JPEG that looks worse.
- Unoutlined text in SVG. The logo renders in a fallback font on any machine without your typeface.
- Missing intrinsic size. Without width and height, the layout shifts as images load.
- Recompressing exports. Exporting from a JPEG to another JPEG stacks the quality loss.
Exercise
A page needs four assets: a one-color search icon, a team photo behind the page header, a screenshot of a dashboard with small table text, and a company logo that appears on both white and dark backgrounds. Choose a format for each and give one reason.
Show answer
Search icon: inline SVG in one color, so CSS can recolor it for hover and disabled states. Team photo: WebP with a JPEG fallback, because photos compress best with lossy formats and WebP gives smaller files. Dashboard screenshot: PNG (or lossless WebP), because lossy compression would blur the small text. Logo: SVG, because it stays sharp at any size and can work on both backgrounds, with a PNG only where SVG is unsupported, such as in email.
Exercise
A developer reports that the logo exported as SVG shows in a different typeface on their machine, and the file is 300 KB. Name two likely causes and the fix for each.
Show answer
First, the text in the logo was left as live text, so the browser substitutes a fallback font. Convert the text to outlines before export. Second, the file is large because it contains editor metadata, hidden layers, or an embedded raster image. Remove unused layers, replace any embedded bitmap with vector shapes, and run an optimizer such as SVGO.