A vector image is a picture stored as a list of shapes (lines, curves, fills and text) described by coordinates, rather than as a grid of coloured pixels. Because the computer redraws those shapes at whatever size you ask for, a vector image stays sharp from a favicon to a billboard.
The common vector format on the web is SVG (Scalable Vector Graphics). The common raster formats are PNG, JPEG, GIF, WebP and AVIF. The rest of this article covers how the two approaches differ, what a vector file contains, and which to pick.
What is a vector image, exactly?
The W3C describes SVG as a language for describing two-dimensional graphics, with three kinds of graphic objects: vector graphic shapes, images and text. MDN describes it as an XML-based, text-based, open web standard for describing images that can be rendered cleanly at any size.
"Text-based" is the useful detail. An SVG file is readable text. This is a complete, valid vector image of a blue square with a circle on it:
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
<rect x="10" y="10" width="80" height="80" fill="#2a5db0" />
<circle cx="50" cy="50" r="25" fill="#ffffff" />
</svg>
Nothing in that file says "100 pixels wide of blue". It says "a rectangle starting at 10,10 that is 80 units across". Set width="1000" instead and the same instructions are drawn ten times larger, with edges as crisp as before. The viewBox attribute defines the coordinate system the shapes live in, and the width and height define the size it is drawn at.
What is a raster image?
A raster (or bitmap) image is a rectangular grid of pixels, and each pixel stores a colour. PNG, JPEG, GIF, WebP and AVIF are all raster formats, according to MDN's image format guide. A photo from a phone is raster, and so is a screenshot.
The grid has a fixed size. A 1920 by 1080 image holds 1920 × 1080 = 2,073,600 pixels. Uncompressed at 24 bits (3 bytes) per pixel, that is 6,220,800 bytes, about 5.9 MiB. Formats such as PNG and JPEG compress that, but the picture is still a fixed set of pixels.
Why raster images go blurry when enlarged
If you display that 1920 by 1080 image at 3840 by 2160, the software has to invent pixels that were never stored. It guesses them by blending neighbours (interpolation), which produces softness or visible blocks. Doubling width and height quadruples the pixel count (2,073,600 becomes 8,294,400), so three out of every four pixels on screen are estimates.
Shrinking a raster image is safe, since you are discarding detail. Enlarging it is where quality is lost. A vector image has no such limit because nothing is estimated: the shapes are recalculated at the new size.
Vector vs raster at a glance
| Property | Vector (SVG) | Raster (PNG, JPEG, WebP, AVIF) |
|---|---|---|
| Stored as | Shapes, paths and text with coordinates | A fixed grid of pixels |
| Scaling up | Stays sharp at any size | Blurs or shows blocks |
| Best for | Icons, logos, diagrams, UI elements | Photographs, screenshots, detailed artwork |
| Photographs | Generally not useful | Standard choice (JPEG, WebP, AVIF) |
| File size | Grows with the number of shapes, not the display size | Grows with the pixel count |
| Editable as text | Yes, it is XML | No |
MDN's guide lists SVG as the format for icons, diagrams and UI elements that must render accurately at any size, and says it is generally not useful for photographic images, although bitmaps can be embedded inside an SVG.
What is inside a vector file: paths
Basic shapes cover rectangles and circles, but most artwork uses the <path> element. Its d attribute holds a sequence of commands, each a letter followed by numbers. MDN documents these:
| Command | Meaning |
|---|---|
M x y | Move to a point without drawing |
L x y | Draw a straight line to a point |
H x / V y | Draw a horizontal or vertical line |
C x1 y1, x2 y2, x y | Draw a cubic Bézier curve with two control points and an end point |
Z | Close the shape by drawing back to the start |
Uppercase letters use absolute coordinates, and lowercase letters are relative to the current position. These two paths draw the same 80 by 80 square:
<path d="M 10 10 H 90 V 90 H 10 Z" fill="none" stroke="black" />
<path d="M 10 10 h 80 v 80 h -80 Z" fill="none" stroke="black" />
Design programs write these commands for you when you draw with a pen or curve tool. The curves are what let a vector logo have smooth round edges at any size.
Common vector file formats
- SVG. The open web standard. Browsers display it directly, and you can style or script it with CSS and JavaScript when it is inlined in a page.
- Other formats. Design and print workflows also use formats such as PDF, EPS and AI. Which of these hold vector data depends on how the file was made, so check what the file actually contains before assuming. This article's sources cover only SVG, so the details of the others are outside its scope.
When to use which
- Use a vector (SVG) for logos, icons, charts, diagrams and simple illustrations, especially if they appear at several sizes or on high-density screens. One file serves every size.
- Use raster for photographs and anything with continuous tone. JPEG is the long-standing choice; MDN says lossy WebP is typically 25 to 35 percent smaller than JPEG and lossy AVIF around 50 percent smaller, and recommends a fallback for browsers that lack support.
- Use lossless raster (PNG) for screenshots and line art that must be exact but is not available as a vector. MDN advises against JPEG for sharp content such as diagrams, because compression artifacts show around edges.
You can offer a vector first and fall back to raster with the <picture> element, the pattern MDN shows:
<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>
If a vector image still looks wrong
Open the file in a text editor. If you see <svg and shape tags, it is a real vector. If the file contains an <image tag with a long data:image/png;base64 string, it is a raster picture wrapped in an SVG container, and it will blur when enlarged like any bitmap. MDN notes that bitmaps can be embedded in SVG, so a .svg extension alone does not guarantee vector content.
Frequently asked questions
- Is a PNG a vector image?
- No. PNG is a raster format: it stores a grid of pixels with lossless compression. A PNG can contain a picture of a logo, but it cannot be enlarged without losing sharpness the way an SVG can. SVG is the common vector format on the web.
- Can I turn a JPEG or PNG into a vector image?
- Only by tracing. Tracing software guesses shapes from the pixels and draws paths around them. It works well on flat logos and line art, and poorly on photographs, because a photo has no clean shapes to find. The result is a new drawing, not the original data recovered.
- Why are photos not stored as vectors?
- A photograph is continuous tone: millions of slightly different colours with no clear edges. Describing that with shapes would need so many paths that the file would be larger and slower than a JPEG. MDN notes that SVG is generally not useful for photographic images.
- Do vector images have a resolution?
- Not in the pixel sense. The file holds coordinates and shapes, so it has no fixed pixel grid. Resolution only appears when the image is rendered to a screen or printer, and it is chosen at that moment.