SVG (Scalable Vector Graphics) is an image format that describes a picture as shapes rather than pixels. An SVG file is a text file in XML: it says "draw a circle here, a line there, fill this area blue", and the browser draws the result at whatever size it's displayed. A PNG of the same logo is a fixed grid of pixels that blurs when it's enlarged; the SVG is simply redrawn.
Here is a complete SVG image, a single diagonal line in a 100-by-100 box:
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<line x1="0" y1="80" x2="100" y2="20" stroke="black" />
</svg>
SVG is a W3C standard. Version 1.1 (Second Edition, 2011) is the latest finished Recommendation; SVG 2 is still a Candidate Recommendation, with its most recent snapshot published on October 6, 2026. All current browsers display SVG. MDN
When to use SVG, and when not to
SVG is the right choice for images that can be drawn from shapes:
- logos and icons;
- diagrams, charts and maps;
- illustrations with flat colors;
- interface elements that need to scale or change color with CSS.
It's the wrong choice for photos. A photo is millions of slightly different pixels, and describing it as shapes makes a huge file. Use JPEG, WebP or AVIF for photos, and see image compression for keeping them small.
Because SVG is text, it compresses well when your server applies Gzip or Brotli. Files exported from design tools, though, can carry editor metadata and needless detail, so run them through an optimizer before you publish.
How to put SVG on a page
There are three common ways, and they behave differently:
| Method | Example | What to know |
|---|---|---|
| As an image | <img src="logo.svg" alt="Acme"> or a CSS background |
Cached like any image; scripts inside the SVG don't run |
| Inline | <svg>...</svg> directly in the HTML |
Can be styled and animated with the page's CSS and JavaScript; no extra request, but not cached separately |
| Embedded document | <object>, <iframe> or <embed> |
Runs as its own document, scripts included |
Serve SVG files with the content type image/svg+xml and the .svg extension.
Security: treat SVG files as code
An SVG file can contain JavaScript and links to other resources. When you show it through <img> or CSS, browsers disable scripts and block external resources, so it behaves like a plain picture. Those limits don't apply when someone opens the file directly or when it's embedded with <object>, <iframe> or <embed>. MDN
So if your site accepts SVG uploads from users, treat them like code: sanitize them, or serve them only as images, ideally from a separate domain.
SVG and SEO
Google indexes SVG. It lists SVG among the image formats it supports in <img> tags and in Google Images, and it can index .svg files themselves. Google Search Central
Give SVG images a text alternative, as you would any image:
- For
<img src="chart.svg">, use the alt attribute. - For inline
<svg>, add a<title>element and point to it witharia-labelledby, the pattern Google's image guide shows:
<svg aria-labelledby="chart-title" role="img">
<title id="chart-title">Monthly visits rose from 2,000 to 5,000 in 2026</title>
...
</svg>
Purely decorative SVGs, like a divider line, need no description; hide them from screen readers with aria-hidden="true". Good text alternatives help both accessibility and image SEO.
One exception to watch: favicons. Many browsers accept SVG favicons, but the formats Google lists for favicons in search results are BMP, GIF, ICO, PNG, JPEG, PPM and TIFF. If your main favicon is an SVG, also link a PNG or ICO version so Google has one it can use.