NewsInsightsDesign

What Is SVG, and How Should You Use It on Your Website?

Illustration of SVG graphics: a vector drop shape with anchor points and a code bracket icon

If a graphic on your site was drawn rather than photographed, it should probably be an SVG (Scalable Vector Graphics) file. SVG is an image format that describes shapes, lines and text as code instead of pixels. Because the browser draws an SVG from those instructions, it stays perfectly sharp at any size, usually weighs very little, and can be styled and animated with CSS and JavaScript. That makes SVG the best choice for logos, icons, illustrations and simple charts on a website.

Websites are viewed on everything from small phones to large high-density displays. Graphics that scale cleanly without extra files and load quickly make a site look sharp and run well on all of them.

This post started in 2014, written by a designer on our team who used Illustrator long before Photoshop and had built for Flash back in the day, so vectors felt natural. At the time, browser support for SVG had finally become good enough to use it widely. Today every modern browser supports SVG, and the advantages of vectors are easier than ever to put to work.

What is SVG?

Raster vs. vector

Most web images are raster images: JPG, PNG, GIF, WebP and TIF files that record the color of every pixel. Enlarge a raster image past its original size and those pixels simply get bigger, which is why it starts to look blurry or blocky.

A vector image is a set of drawing instructions. An SVG might say, in effect, “at coordinates 40, 80, draw a rectangle 400 wide and 300 tall and fill it with blue.” The browser renders those instructions fresh at whatever size is needed, so there are no pixels to stretch. That’s exactly what responsive design needs. Icons look crisp on every screen, including retina and other high-density displays.

The more useful part is that those vector instructions can live directly in the DOM (Document Object Model), the structure the browser builds from your page. That means you can style and manipulate a graphic on the fly, just like any other element.

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
  <circle cx="50" cy="50" r="40" fill="#f2a900" />
</svg>

That short snippet is a complete SVG. It draws a yellow circle that looks equally crisp as a 16-pixel icon or a full-screen graphic.

Is SVG HTML or XML?

SVG is an XML-based markup language and an open W3C standard, so an .svg file is plain text you can open, read and edit. It isn’t HTML, but the two work closely together. HTML lets you paste SVG markup directly into a page (called inline SVG), and the browser treats each shape as part of the document. That’s why CSS and JavaScript can reach inside an inline SVG.

Why use SVG on your website?

  • Sharp at any size: One file looks crisp on standard screens, high-density “retina” displays and everything in between, which suits responsive layouts that resize constantly.
  • Small files for simple graphics: Logos and icons are often just a few kilobytes, and because SVG is text, it compresses well with gzip or Brotli on the server.
  • Styling and animation: Inline SVG elements can be targeted with CSS, so you can change colors on hover, support dark mode or animate a stroke without making new image files.
  • Interactivity: Each shape in an SVG can carry an ID or class and respond to clicks, which makes SVG useful for maps, diagrams and data visualizations.
  • Accessibility and search: SVG can include a title and description, and text inside an SVG stays real text rather than pixels.

We’ve used this flexibility on client work. For a property development company, we built a floor plan viewer where a visitor first chooses a unit type (studio, one bedroom, two bedrooms and so on), then picks a specific unit to see its drawings and details. Each unit is its own shape inside the SVG, with an ID and class. Choosing a type activates the matching units, hover and active states show what’s selectable, and a click event swaps in the right floor plan, all from one lightweight graphic.

SVG vs. PNG, JPG and WebP

Choosing a format comes down to what the image contains. A quick guide:

  • SVG: Logos, icons, illustrations with flat color, line art, simple charts and anything you want to animate or recolor.
  • PNG: Raster graphics that need sharp edges or transparency, such as screenshots, when a vector version isn’t available.
  • JPG: Photographs, where smooth color variation matters more than crisp edges.
  • WebP (or AVIF): Modern formats for photos and complex images that usually produce smaller files than JPG or PNG at similar quality.

Our rule of thumb is simple. If the image was drawn, use SVG. If it was photographed, use a raster format.

How to add SVG to a website

How you implement SVG matters as much as whether you use it. There are three common ways to use SVG in HTML and CSS, and each has trade-offs. CSS-Tricks keeps a thorough rundown of different techniques for using SVG if you want to go deeper.

1. As an image with the img tag

This is the simplest option and works like any other image. The browser downloads the file once and caches it, so it’s ideal for a logo or complex graphic that appears on every page. The object tag works similarly and also lets the browser cache the file. The trade-off is that you can’t style the shapes inside it with your page’s CSS.

<img src="/images/logo.svg" alt="Company name" width="160" height="40">

2. Inline in the HTML

Pasting the SVG code directly into the page puts every shape in the DOM, so you can style it with CSS, run transitions and control it with JavaScript. The big drawback is that inline SVG never caches on its own. Visitors download that code again with every page load. If you’re building a single-page site, or the SVG is simple or appears only once, this is the method to use. For a full icon set, an SVG sprite with the use element is a good middle ground, as explained in this guide to SVG sprites.

<button class="icon-button">
  <svg viewBox="0 0 24 24" width="24" height="24" aria-hidden="true">
    <path d="M4 12h16M12 4v16" stroke="currentColor" stroke-width="2" />
  </svg>
  Add item
</button>

Setting the stroke or fill to currentColor makes the icon match the surrounding text color, so it changes automatically on hover or in dark mode.

3. As a CSS background image

For decorative patterns, dividers and textures that carry no meaning, a CSS background keeps the markup clean and the file cached.

.hero {
  background-image: url("/images/wave-pattern.svg");
  background-size: cover;
}

What about SVG JavaScript libraries?

When this post was first written, libraries like Raphaël were the go-to way to draw and animate SVG with JavaScript, and its demos are still a fun look at what’s possible. Raphaël dates from the era of old Internet Explorer, which it supported through a fallback, and it has seen little development in recent years. For new projects, most teams use native SVG with CSS animations, or modern libraries such as Snap.svg (from Raphaël’s creator), D3.js for data visualization and GSAP for complex animation.

Can I use SVG as an icon?

Yes. SVG icons are the modern standard for websites and apps, and they’ve largely replaced icon fonts. They stay sharp at every size, can be recolored with CSS, and are more reliable and more accessible than font-based icons. You can add them one at a time with an img tag, inline them for full styling control, or combine a set into a sprite. Most modern browsers also accept an SVG favicon, though it’s still wise to provide a PNG or ICO fallback for platforms that don’t.

Where to find SVG icons

Established open-source icon sets are a safer starting point than random download sites. Well-maintained options include Google’s Material Symbols, Bootstrap Icons, Heroicons, Lucide and Feather. Before you use any icon set, check its license, keep the style consistent across your interface, and run the files through an optimizer. For a brand with a distinct personality, a custom icon set designed alongside your visual identity is often worth the investment.

What program opens and edits SVG files?

Any modern web browser can open an SVG file. Drag it into Chrome, Firefox, Safari or Edge to view it. To create or edit one, you have several options:

  • Figma: A browser-based design tool with a free plan, widely used for interface design and icon work. It imports and exports SVG.
  • Adobe Illustrator: The long-standing professional vector tool, with detailed SVG export settings.
  • Inkscape: A free, open-source desktop editor that uses SVG as its native format, and one of the best free SVG editors available.
  • Affinity Designer and Sketch: Popular vector design apps that also export SVG.
  • A code editor: Because SVG is text, you can open and hand-edit it in any code editor, which is handy for small tweaks like changing a color.

If you need a free online SVG editor, Figma’s free plan runs in the browser, and open-source projects such as SVG-Edit offer simple editing without installing anything.

Can AI tools generate SVG?

Yes, within limits. Because SVG is text, AI chat assistants such as ChatGPT and Claude can write SVG code for simple icons, shapes and diagrams, and design tools like Illustrator now include generative features that produce editable vectors from a text prompt. The results are useful for drafts and placeholders, but they often need cleanup: extra or messy paths, missing accessibility labels and styles that don’t match your brand. Treat AI-generated SVG as a starting point, then review, optimize and test it like any other asset.

How to optimize SVG files

SVGs exported from design tools like Illustrator or Figma often include editor metadata, hidden layers and overly precise coordinates. Cleaning them up can noticeably shrink the file and speed up rendering. A practical checklist:

  • Run files through SVGO, an open-source optimizer that strips unneeded data. Many build tools and plugins use it behind the scenes.
  • Simplify paths and merge shapes in your design tool before exporting.
  • Keep the viewBox attribute so the graphic scales correctly.
  • Convert text to outlines only when the font isn’t available on the site; otherwise keep live text for accessibility.
  • Make sure your server compresses SVG files with gzip or Brotli.
  • Treat SVG uploads from untrusted users with care, since SVG files can contain scripts. Sanitize them or limit uploads to trusted editors.

Image weight is only one part of a fast site. Our post on the process of site performance covers the bigger picture.

How to make SVG accessible

Screen readers need to know whether an SVG carries meaning or is purely decorative. For an SVG loaded with an img tag, write a useful alt attribute, or use an empty alt for decoration. For inline SVG that conveys information, add role=”img” and a title element, referenced with aria-labelledby.

<svg role="img" aria-labelledby="chart-title" viewBox="0 0 400 200">
  <title id="chart-title">Monthly site visits, January to June</title>
  <!-- chart shapes -->
</svg>

For decorative inline icons, add aria-hidden=”true”, as in the button example above, so screen readers skip them. Also check that colors inside the SVG meet contrast requirements, just like the rest of your interface. The MDN SVG documentation is a reliable reference for elements and attributes.

When not to use SVG

SVG isn’t the right tool for every image. Photographs and photo-realistic artwork belong in JPG, WebP or AVIF. Tracing them as vectors produces huge files and poor results.

Very complex vectors can also hurt SVG rendering performance, because the browser has to parse every path, gradient and filter on each paint. Graphics with gradients, drop shadows and other filters and effects are often better as raster images, and heavy use of blurs and thousands of points can slow loading, scrolling and animation on lower-powered devices. When a graphic gets that detailed, compare it against a raster version and use whichever is lighter and smoother.

Sometimes the answer is both. Mapping is a popular use for interactive SVG, and we used an SVG map in a web-based iPad game. SVG files are only smaller than rasters for simple shapes. A detailed map of the entire world is actually lighter as a raster image. We also wanted a smooth zoom when a user selected one of six countries, and large-scale zooming in a browser can cause rendering hiccups that make an animation look slow or jittery, depending on the device and the complexity of the image.

So we used two layers: a PNG of the entire world map, and an SVG layer on top with only the six countries. When a user picks a country, the rest of the map fades away and that country zooms in. The country stays crisp because it’s a vector, and the zoom stays smooth because we simplified what actually moves.

Browser support used to be another reason to skip SVG. When this post was first written, Internet Explorer 8 didn’t support SVG at all, so we had to create PNG fallbacks. Internet Explorer has since been retired, and fallbacks are rarely needed today outside of special cases such as some email clients.

Further reading

There are many great resources for learning more. A few of our go-tos:

Getting SVG right

SVG works best when design decisions and front-end development happen together. That’s how our design team and development team approach graphics on every site we build.

Use SVG for anything drawn, such as logos, icons, illustrations and simple charts, and raster formats for anything photographed. Optimize the files, label them for accessibility, and your graphics will stay sharp and fast on every screen.

Newsletter

Sign up for the Daylight Newsletter to receive helpful blog posts, insights and featured client projects.

Our Clients

Wacom Logo
Webtrends Logo
Nike Logo
Trinchero Logo
Sutter Home Logo
Ste. Michelle Logo
SheerID Logo
Providence Logo
Newmans Own Logo
Marchex Logo
Intel Logo
Black and decker Logo
Brooks Logo
Coca-Cola Logo
Dakine Logo
No Kid Hungry Logo
American Red Cross Logo
Jackson Family Wines logo
Argyle Winery logo
Wente Vineyards logo
Evanta a Gartner Company
Coeur d’Alene Resort Logo
Travel Oregon Logo
Stanley Logo
Superhuman Logo