SVG describes graphics as shapes and coordinates rather than as a grid of pixels, which means it scales to any size without losing sharpness and is usually tiny for simple artwork. There are three ways to get it onto a page and they behave very differently.
As an image file
The simplest approach treats it like any other image.
<img src="/assets/icons/search.svg" alt="Search" width="24" height="24"> This is clean, cacheable and keeps the markup short. The file is requested separately, so it can be cached across pages and it does not bloat your HTML.
The limitation is that CSS on your page cannot reach inside it. You cannot change the fill colour, animate a path or restyle part of the graphic, because as far as the document is concerned it is an opaque image. Any styling must be inside the file itself.
Inline in the document
Pasting the SVG markup directly into the page makes its shapes part of the document tree.
<svg viewBox="0 0 24 24" width="24" height="24" aria-hidden="true"> <path d="M10 2a8 8 0 105.3 14l5.4 5.4 1.4-1.4-5.4-5.4A8 8 0 0010 2z"/> </svg> Now CSS and JavaScript can address the individual shapes. Setting the fill to currentColor makes an icon inherit the text colour of its container, which is why inline SVG is the standard approach for icon systems: one file serves light and dark themes and every button state without producing a variant for each.
The costs are that the markup is repeated wherever the icon appears, it cannot be cached separately, and a complex illustration inlined into every page adds real weight. Icons are worth inlining. A detailed illustration usually is not.
As a CSS background
The third option references it from a stylesheet.
.icon-search { background-image: url("/assets/icons/search.svg"); } This suits purely decorative graphics and keeps the markup clean. Like the image element approach, the page CSS cannot reach inside it. Because a background image is invisible to assistive technology, it is the right choice only when the graphic carries no information at all.
The viewBox is what makes it scale
The viewBox attribute defines the coordinate system of the graphic, and without it an SVG will not scale properly. It takes four numbers: the origin coordinates followed by the width and height of the drawing area.
With a viewBox present, setting a width in CSS scales the whole graphic to fit. Without one, the SVG has fixed dimensions and ignores your sizing. This is the single most common reason an SVG refuses to resize, and the fix is to add the attribute rather than to fight it with CSS.
Accessibility
How you make an SVG accessible depends on how it is embedded, and on whether it means anything.
A decorative graphic should be hidden. For an image element that means an empty alt attribute. For inline SVG it means an aria-hidden attribute set to true.
A meaningful graphic needs a name. An image element takes ordinary alt text. Inline SVG needs an explicit role of img plus either a title element as its first child or an aria-label attribute. Without one of those, support varies and the graphic may be announced as nothing or as a meaningless element name.
The most common case is an icon inside a button that already has a text label, in which case the icon is decorative and should be hidden so the label is not announced twice.
Sprites and symbol references
Repeating the same inline icon dozens of times bloats a page. The established solution defines each icon once as a symbol inside a single SVG block, then references it wherever needed with a short use element pointing at its identifier.
This keeps the styling benefits of inline SVG while writing the path data only once. The sprite can live at the top of the page or in a separate file, though referencing an external file has caching advantages and slightly more awkward browser support to check.
Sanitise anything you did not draw
SVG is XML and can contain scripts, external references and event handlers. An inline SVG runs in the context of your page, so accepting an uploaded SVG and inlining it is equivalent to accepting arbitrary markup from a stranger.
Run anything from an untrusted source through a sanitiser, or serve it via an image element, which does not execute scripts. Files from your own design tools are fine, though they usually carry a great deal of editor metadata that an optimiser will strip, often halving the file size for no visual change.