Skip to content

SVG Illustrations

Inline SVG or an img tag? It depends what has to reach inside.

Hero art, feature rows, empty states and spot illustrations — website art that weighs what a paragraph weighs. How you embed it decides whether CSS can theme it, whether a screen reader announces it, and whether it caches.

the same hero illustration

  • PNG @1x180 KB
  • PNG @2x640 KB
  • WebP @2x210 KB
  • SVG22 KB
  • SVG, optimised14 KB

Indicative figures for one flat illustration. The ratio holds for flat art; it inverts for photographic sources.

Four ways in

Inline, img, background, object.

One question settles it nearly every time: does anything outside the file need to reach inside it? Styling, theming, animation and per-element targeting all require inline. Nothing else does.

Inline <svg>

Small, above the fold, or anything that has to restyle or move.

You gain

Page CSS reaches every node. currentColor, CSS variables, hover states, animation, per-element ids to target. No extra request.

You give up

The markup lives in the HTML, so it is re-sent on every page load rather than cached separately, and every path becomes a DOM element.

<img src="art.svg">

Large art, anything repeated across pages, anything static.

You gain

Cached like any other image, kept out of the DOM entirely, and alt text works the way screen readers expect. Lazy-loadable with one attribute.

You give up

Isolated from the page: external CSS and JavaScript cannot reach inside it, so currentColor and theme variables do nothing.

CSS background-image

Dividers, textures, ornamental flourishes.

You gain

Out of the document altogether, which is right for decoration. Can be swapped per breakpoint or per theme in the stylesheet.

You give up

Invisible to assistive technology — correct for ornament, wrong for anything carrying meaning. Same styling isolation as an img.

<object> or <embed>

Effectively legacy — reach for inline or img instead.

You gain

Loads as its own document, so scripts and styles inside the file run.

You give up

Awkward fallbacks, an extra browsing context, and accessibility that behaves differently across screen readers. Rarely the right answer now.

Budgets by placement

What each slot on a page can afford.

Not rules — starting points. The path count matters as much as the byte count when the illustration is inlined, because every path is a DOM node.

Illustration placements with size and path count budgets
PlacementByte budgetPathsNotes
Hero illustration15 – 40 KB60 – 200Above the fold and in the LCP path. Inline it so it paints with the HTML, and keep the palette to four or five values.
Feature row art3 – 10 KB15 – 50Three or four of these appear together, so the budget is per item multiplied by the row. Share one style across all of them.
Empty state4 – 12 KB20 – 60Rendered rarely and never on first paint. Lazy-load it; there is no reason for it to be in the initial bundle.
Spot iconunder 2 KBunder 15Small enough to inline anywhere. Use currentColor so it inherits text colour with no extra work.
Background patternunder 2 KBone tileDefine the tile once as a pattern and repeat it. A repeated tile is one definition however large the area.
Decorative dividerunder 1 KB1 – 5Purely ornamental, so it belongs in CSS as a background image and out of the document entirely.

Why vector on the web

Six things a PNG cannot do.

Sharp at every density

One file covers 1×, 2× and 3× displays. No @2x variant, no srcset, no decision about which raster size to ship.

Themeable after the fact

Fills are attributes, so a CSS variable or a currentColor reference recolours the whole illustration for dark mode without a second asset.

Small enough to inline

Under a few kilobytes an illustration can live in the HTML and cost zero requests — which matters most for the one image above the fold.

Animatable in place

A stroke can draw itself, a group can drift, a colour can transition. All of it in the same file, with no video and no library.

Accessible by construction

A title element gives the illustration a name; aria-hidden removes it from the tree when it is decoration. Both are one attribute.

Diffable in a repo

It is text. Reviewers can see that a colour changed rather than staring at two binaries and taking your word for it.

The pattern

Responsive, themeable, named — in eight lines.

Drop the width and height, keep the viewBox, reference CSS variables in the fills, and give the illustration a title if it carries meaning. That is the whole technique.

How viewBox scaling works
hero.svg
<svg
  viewBox="0 0 800 600"
  role="img"
  aria-labelledby="hero-title"
  class="w-full h-auto">
  <title id="hero-title">
    Two people assembling a chart
  </title>
  <g id="figures" fill="var(--brand)">
    <path d="M120 480 C 160 380, …"/>
  </g>
  <g id="chart" fill="currentColor">
    <rect x="480" y="220" …/>
  </g>
</svg>

The other side

Six disadvantages worth knowing.

None of these is a reason to avoid vector for interface art. They are the cases where it is the wrong tool, and knowing them is most of the skill.

Node count is the real cost

An inlined illustration with 900 paths adds 900 DOM elements for layout and paint to walk. This, not file size, is what makes a heavy SVG feel slow.

Photographs are the wrong job

Trace a photo and you get thousands of paths that are larger and worse-looking than the JPEG you started with. Flat and geometric artwork is where the maths favours vector.

Text substitutes silently

Live <text> renders in whatever font is available. Outline the letterforms unless you control the font everywhere the file will be seen.

It is executable markup

SVG can carry script, so an uploaded file from a stranger is a real attack surface. Sanitise anything user-supplied before you inline it.

Rendering is not pixel-identical

Filters, blend modes and complex masks vary between engines. Ordinary shapes are consistent; the exotic features are worth checking.

Editor exports are bloated

A Figma or Illustrator export carries frames, transforms and metadata you do not need. Untouched, it can be several times the size it should be.

And one thing we are not: a library. Every illustration here starts from a prompt, so if you want something ready-made and free, unDraw, DrawKit, Lukasz Adam, Icons8 and Flowbite are the sets most projects reach for first. Generation earns its place when you need something specific, or a matching set nobody else is shipping.

Questions

Inlining, embedding and SVG against PNG.

What is an inline SVG?
An SVG written directly into the HTML as markup rather than referenced as a file. Because the shapes become part of the document, your stylesheet and scripts can reach them — which is the whole reason to do it, and the whole reason not to when you do not need it.
Is it better to use SVG or PNG for websites?
For flat, geometric and interface artwork, SVG: smaller, sharp at every density, themeable and animatable. For photographs and heavily textured images, PNG or JPEG wins outright, and a traced photograph is usually both larger and worse-looking than the original. Pick by what the image is, not by a general preference.
What are the disadvantages of using SVG?
Six worth knowing: node count rather than file size is the real performance cost; photographs trace badly; live text substitutes fonts silently; SVG can carry script so user-uploaded files need sanitising; filters and blend modes render slightly differently across engines; and design-tool exports arrive bloated. None of these is a reason to avoid it for interface art — they are the cases where it is the wrong tool.
Where can I download free SVG illustrations?
unDraw, DrawKit, Lukasz Adam, Icons8 and Flowbite all publish free sets, most under permissive licences. We are a generator rather than a library — nothing here is pre-drawn — so if a ready-made illustration is what you want, start with those. Generation is the better route when you need something specific, or a matching set nobody else is already using.
Are SVG illustrations always smaller than PNG?
For flat and geometric artwork, dramatically — often ten times smaller, and sharp at every density on top of that. For photographic or heavily textured art the relationship inverts, which is a reason to keep illustration styles flat rather than a reason to ship PNG.
Should I inline the SVG or use an img tag?
Inline when you need CSS control, animation or currentColor, and when the file is small enough that adding it to the HTML is cheaper than a request. Use an img tag when the illustration is large, repeated across pages, static, or wants to be lazy-loaded and cached separately. The deciding question is whether anything outside the file needs to reach inside it.
How do I handle dark mode?
Reference CSS custom properties or currentColor in the fills, then let your existing theme switch repaint them. One file, both themes, no duplicate asset.
Do SVG illustrations hurt performance?
Only through node count. An inline illustration with 900 paths adds 900 DOM elements that layout and paint have to walk. Keep the path count low and optimise before shipping and the cost is negligible.
Can I make a matching set?
Yes — keep the style, palette and stroke clauses of your prompt identical and vary only the subject. Then do a consistency pass in the editor so every piece uses the same colour values exactly.
How do I make one responsive?
Keep the viewBox, drop width and height, and let CSS size the container. preserveAspectRatio controls how the art fits when the container's ratio does not match the viewBox.

Replace the hero PNG this afternoon.

Generate an illustration