When you add a logo, an icon or a photo to a web page, one of the first decisions is which type of image to use. Broadly, images fall into two families: raster and vector. The difference affects sharpness, file size, flexibility and even page speed. This guide explains how each type works, where each one shines and how to avoid common mistakes.
What Is a Raster Image?
A raster image is a grid of tiny colored squares called pixels. Photographs, screenshots and most pictures from cameras are raster images. Common raster formats include JPG, PNG, GIF, WebP and AVIF.
The key property of raster images is that they have a fixed resolution. A 400-pixel-wide image has exactly 400 columns of pixels. If you enlarge it beyond its natural size, the software must invent new pixels, and the result looks blurry or blocky.
Strengths:
- Perfect for photographs and complex images with rich color gradients.
- Supported everywhere.
Weaknesses:
- Quality depends on resolution.
- File size grows quickly as dimensions increase.
- Different screen densities require multiple versions.
What Is a Vector Image?
A vector image describes shapes mathematically: lines, curves, polygons and fills. Instead of storing each pixel, it stores instructions such as "draw a circle here with this radius and color". The most common vector format on the web is SVG, which stands for Scalable Vector Graphics.
Because the image is a set of instructions, it can be scaled to any size, from a tiny icon to a giant billboard, without losing sharpness. It always looks crisp, on any screen density.
Strengths:
- Infinitely scalable with no loss of quality.
- Often very small files for simple graphics.
- Can be styled and animated with CSS and JavaScript.
- Text inside SVG can remain selectable and searchable.
- Easy to change colors, such as switching an icon to a dark mode color.
Weaknesses:
- Poor fit for photographs and very complex scenes. An SVG that tries to reproduce a photo can become enormous.
- Can contain scripts, so untrusted SVG files must be handled carefully.
When to Use SVG
- Logos and brand marks.
- Icons and user interface symbols.
- Simple illustrations and diagrams.
- Charts and data visualizations.
- Decorative shapes and dividers.
- Anything that has to look sharp at many sizes.
When to Use Raster Images
- Photographs of people, places and products.
- Screenshots.
- Images with complex textures, lighting and gradients.
- Artwork where hand-painted detail matters.
For photographs, use JPG, WebP or AVIF. For screenshots or sharp graphics that need transparency and cannot be vector, use PNG or lossless WebP.
Ways to Add SVG to a Web Page
- As an image file: use an img tag with the SVG as the source. It is simple, cacheable and works like any other image, but you cannot style its internal parts with page CSS.
- Inline SVG: paste the SVG code directly in the HTML. You can style it with CSS, animate parts of it and change colors using the page's variables. It avoids an extra request, but increases the size of the HTML and cannot be cached separately.
- As a CSS background image: useful for decorative elements.
- In an object or embed element: allows interactivity and external styling but is used less often now.
For icons that must match your theme, including dark mode, inline SVG with colors defined as "currentColor" is a very flexible approach.
Performance Considerations
SVG files for simple graphics are often only a few kilobytes. You can reduce them further by removing unnecessary metadata that design software adds, simplifying paths and rounding coordinates. Servers should compress SVG with gzip or Brotli, since it is text. On the other hand, a complicated SVG with thousands of paths can be slower to render than an equivalent raster image, so test heavy graphics on low-powered devices.
Accessibility
Treat SVGs like any other image. If the graphic conveys information, add a text alternative: alt text when using an img tag, or a title and a role of img with a label when using inline SVG. If the graphic is purely decorative, hide it from assistive technology.
Security Warning
An SVG file is really an XML document and can contain scripts and external references. Never display or accept SVG uploads from untrusted users without sanitizing them first. Serving user-uploaded SVG directly can create cross-site scripting risks. If you only ever need raster uploads, restrict your upload form to JPG, PNG and WebP.
Common Mistakes
- Using a large raster logo and scaling it down in CSS instead of using an SVG.
- Converting a photograph into SVG expecting smaller files. The result is usually bigger.
- Exporting from design software with excessive embedded data and never cleaning it.
- Forgetting to set a
viewBox, which makes SVGs hard to scale responsively. - Using raster icons at one size and finding them blurry on high-density displays.
A Quick Decision Guide
- Is it a photograph? Use a raster format.
- Is it a logo, icon or simple illustration? Use SVG.
- Do you need it to change color with your theme? Use inline SVG.
- Is the SVG file bigger than a comparable PNG? Reconsider, or simplify the graphic.
Converting Raster Formats
When you need to switch between JPG, PNG, WebP and AVIF for your photographs and screenshots, our free Image Format Converter does it in your browser, with no uploads.
Final Thoughts
Vector and raster images are not competitors. They are tools for different jobs. Use SVG for crisp, scalable graphics and raster formats for photographs, and your site will look sharper while loading faster.