A vector graphic is just math, so it stays razor-sharp at any size and weighs a fraction of a photo. That makes SVG the right choice for logos, icons, and diagrams, but only if you embed it the right way, strip the bloat, and sidestep the handful of traps that make a “sharp” format look fuzzy.
<img> for simple, cacheable graphics; inline <svg> when you need CSS/JS control; <use>/sprites for repeated icons. Optimize with SVGO, a tight viewBox, and fewer decimal places. And if an SVG looks blurry, it’s almost always a raster image trapped inside it or a missing/incorrect viewBox, not the format’s fault.Because a vector is defined by geometry, not a grid of pixels, it renders sharp on any screen at any zoom and compresses to a fraction of an equivalent PNG. That’s why this very site draws its diagrams as SVG. The catch is that “use SVG” isn’t one decision. It’s three: how to embed it, how to slim it, and how to keep it crisp.
Simplest; browser caches it like any image. But your CSS and JS can't reach inside to recolor or animate. Best for static graphics reused as-is.
Markup lives in the HTML, so CSS and JS have full control (hover, theming, animation). Not cached separately; adds HTML weight. Best for interactivity.
Many icons in one hidden symbol sheet, referenced by id. One cached request serves the whole set. Best for icon systems.
Table of Contents
Why SVG, and when not to
SVG wins wherever the artwork is geometric: logos, icons, UI glyphs, charts, and line diagrams. It scales without blurring, styles with CSS, animates with JavaScript, and stays small. Where it loses is photographs. A photo is millions of irregular pixels, which SVG can’t represent efficiently; that’s what WebP/AVIF are for (see finding and creating website images). Rule of thumb: drawn art → SVG; photographs → raster.
Drawn art wants SVG; photographs want raster. The dividing line is geometry versus pixels.
How to embed it: three methods, three trade-offs
There’s no single “right” way to put an SVG on a page, so match the method to what you need:
<img src="icon.svg">— simplest, and the browser caches it like any image. But your page’s CSS and JavaScript can’t reach inside it to recolor or animate. Best for static graphics you reuse as-is.- Inline
<svg>…</svg>— the markup lives in your HTML, so CSS and JS have full control (hover states, theming, animation). The cost: it isn’t cached separately and adds weight to the HTML. Best when you need interactivity or dynamic styling. <use>/ sprites — define many icons once in a hidden symbol sheet and reference each by id. One cached request serves a whole icon set. Best for icon systems.
<!-- 1. As an image: simple + cached, no CSS control -->
<img src="logo.svg" alt="Company logo" width="160" height="40">
<!-- 2. Inline: full CSS/JS control -->
<svg viewBox="0 0 24 24" role="img" aria-label="Search"><path d="…"/></svg>
<!-- 3. Sprite: one file, many icons referenced by id -->
<svg><use href="/icons.svg#search"></use></svg>
Code language: HTML, XML (xml)
“Use SVG” isn’t one decision.
<img>buys caching, inline buys control, sprites buy reuse. Pick per job.
Keep it accessible and responsive
Two things make an embedded SVG behave:
- Accessibility. Give meaningful graphics a name:
alton<img>, orrole="img"plusaria-labelon inline SVG. Decorative ones can be hidden from assistive tech. - Responsiveness. Always set a
viewBox, then size with CSS (width: 100%; height: auto). TheviewBoxdefines the internal coordinate system so the graphic scales correctly instead of clipping.
Optimize it: smaller and faster
Exported SVGs are full of editor cruft. Trim it:
- Run SVGO. One command strips metadata, comments and hidden elements, often cutting file size by half or more:
svgo icon.svgCode language: Bash (bash)
- Cut decimal places. Coordinates like
12.038471can round to12.04with no visible change. - Simplify and combine paths. Fewer, merged paths mean fewer elements to parse.
- Convert text to outlines when you need identical rendering everywhere (at the cost of selectable text).
- Gzip/Brotli on the server, and use sprites to collapse many icon requests into one; both are part of ordinary performance work.
Fix the blur (and other display traps)
SVG is a sharp format, so a blurry SVG almost always means one of these:
- A raster image is trapped inside the SVG. An embedded PNG/JPEG inside an
<svg>blurs when scaled, because the vector wrapper doesn’t make a bitmap vectorial. Replace it with real vector shapes. - Missing or wrong
viewBox. Without a correctviewBox, the browser can’t scale the coordinate system, so the graphic distorts or clips. Add one that matches the artwork’s bounds. - Fixed pixel dimensions fighting CSS. Prefer
viewBox+ percentage sizing over hard-coded width/height that conflict with your layout. - Heavy filters/transforms. Excessive blur/filter effects can soften edges; simplify them.
Then test across a couple of browsers. SVG support is excellent everywhere, but complex features are worth a quick cross-check.
A blurry SVG is never the format’s fault — it’s a raster trapped inside it, or a missing viewBox.
The short version
SVG describes art as geometry, so it stays crisp at any size and stays tiny, ideal for logos, icons and diagrams, wrong for photographs. Embed it to match the need: <img> for simple cacheable graphics, inline <svg> for CSS/JS control, <use>/sprites for icon sets. Always set a viewBox and size with CSS for responsiveness, and name graphics for accessibility. Optimize with SVGO, fewer decimals, merged paths and server compression. And if an SVG looks blurry, look for a raster image trapped inside it or a missing viewBox; the format itself never blurs.
Frequently Asked Questions
Why does my SVG look blurry if it’s supposed to be sharp?
Almost always because a raster image (PNG/JPEG) is embedded inside the SVG, or the viewBox is missing or wrong. A vector wrapper doesn’t make a bitmap scalable. Replace embedded rasters with real vector shapes and add a correct viewBox.
What is the viewBox and why does it matter?
The viewBox defines the SVG’s internal coordinate system and bounds. With it set, the graphic scales correctly to any CSS size; without it, the browser can’t map the drawing to the display size, so the SVG clips, distorts, or won’t scale responsively.
How do I change an SVG icon’s color with CSS?
Inline the SVG (or reference it with <use>) and set its fill or stroke to currentColor. The icon then takes the CSS color of its parent, so one rule recolors it for hover states or dark mode. This doesn’t work through <img>, because the page’s CSS can’t reach inside an image.
Is it safe to let users upload SVG files?
Not without sanitizing them. An SVG is XML and can carry scripts and event handlers, which is why WordPress blocks SVG uploads by default. Accept uploads only from trusted users, and run each file through an SVG sanitizer before it is stored. Serving untrusted SVGs through <img> is safer, since scripts inside an image don’t run.