SVG to Base64 Converter
Drag in an SVG and instantly get its Base64 string and data URI —
ready to paste into a CSS background-image, HTML or JSON. One click to copy.
100% client-side. Your SVG never leaves your device.
Drop an SVG here
or paste from clipboard · vector stays crisp at any size
SVG to Base64, explained
Encoding an SVG produces a plain-text string that carries the whole drawing. That string can live inside a
stylesheet, an HTML attribute, or a JSON payload, with no second request and no file to host. This page reads
the file with FileReader, converts the bytes to Base64, and gives you both the bare string and a
finished data:image/svg+xml;base64,... URI. Because SVG is
resolution-independent, an inlined icon stays sharp at any size and on any pixel density —
the reason this trick is so common for UI assets.
What the encoder actually does
Base64 maps every three bytes to four ASCII characters, so the output is about a third longer than the input
and contains nothing but A-Z, a-z, 0-9, +,
/, and =. That alphabet is the point: it survives being pasted into CSS, dropped
into a JSON string, embedded in an HTML attribute, or wrapped across lines by a formatter, without any
character needing an escape. The trade is size — a 2 KB icon becomes roughly 2.7 KB of text.
The encoding is mechanical and lossless. Attribute order, comments, whitespace, and precision in
d path data all come through unchanged, because nothing parses the markup. That also means
minifying before encoding pays off directly: every byte you strip from the source saves about 1.33 bytes in
the output.
Base64 or URL-encoding: pick per case
SVG is text, so there are two ways to inline it. Base64 is what this tool emits. It is the
most copy-paste-safe option and the least likely to break when a build step, a CMS, or a templating engine
touches the string. Percent-encoding produces a shorter result — often noticeably so, since
most of an SVG is ordinary ASCII that survives unescaped — but it fails on the details: an unescaped
# in a colour value truncates the URI at a fragment, and unquoted " or newlines
inside a CSS url() will break the declaration.
Use percent-encoding when you control both ends and want the smallest possible string. Use Base64 when the asset passes through systems you do not control, when it goes into JSON, or when someone else will paste it by hand. The two forms are interchangeable at render time, and this page gives you the Base64 side while Base64 to SVG goes back the other way if you inherit a string and need the markup.
Where the string goes
Three placements cover almost every real use:
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxu..." alt="icon" width="24" height="24" />
.icon { background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxu...); }
<style>@font-face { src: url(data:font/woff2;base64,...) format("woff2"); }</style>
The <img> form is the simplest and works in every current browser. The CSS form is what
you want for decorative marks, hover states, and pseudo-element icons where adding an element is awkward. The
@font-face line is a different asset type, but it is the same mechanism — a data URI in a
url() slot — and it is worth knowing that the browser caches an inlined font or image as part of
the stylesheet rather than as a separate resource.
One consequence of inlining is that the data travels with the CSS. A 40 KB icon set inlined into a stylesheet blocks rendering until that stylesheet arrives, where forty separate requests might have loaded in parallel. For one or two small marks the trade is clearly good; for a full sprite sheet it usually is not. If total page weight is the concern, the Base64 size calculator shows what the encoding overhead costs before you commit.
What stops working inside an image tag
An SVG loaded through <img> or CSS url() is treated as an image, not as a
document. That sandbox is what makes inlined SVG safe, and it is also what silently disables features people
expect to keep:
- Scripts and event handlers do not run.
<script>is ignored, and attributes likeonclickare inert. - External resources are not fetched. Linked fonts, remote images, and
xlink:hrefreferences to other files fail. - SMIL animation often does not play, and CSS animations inside the SVG are unreliable across browsers.
- Interactivity is gone — no hover states, no
:targettricks, no tooltips.
If you need any of that, the SVG has to be inlined as markup in the DOM — an actual
<svg> element in the HTML — not wrapped in a data URI. Base64 encoding is the right tool
for static marks and the wrong one for animated or interactive graphics. Note that encoding does not sanitize
either: scripts inside the source are still present in the decoded bytes, so a file from an untrusted source
needs cleaning before you ship it, whatever form you deliver it in.
When to inline an SVG
- Small UI icons and logos that must stay crisp on every display.
- CSS backgrounds where a separate request costs more than the bytes.
- Self-contained components, HTML emails, and design tokens passed between tools.
- Favicons, where a data URI avoids a request that blocks on every page load.
The favicon case has its own constraints — some browsers want a specific MIME type and a raster fallback — covered in Base64 favicon. When a whole page needs to be portable as one file, embedding images in a single HTML file shows the general pattern.
Size, caching, and the gzip question
Base64 costs about 33 percent on the wire, but that is the uncompressed figure. Text compresses well, and a server that gzips or brotli-compresses HTML and CSS shrinks the encoded payload substantially — often back near the size of the original binary. The overhead is worst when the data URI sits in a file that is served uncompressed, or in a context that is re-sent on every navigation.
Caching is the other half. A separate .svg file is cached independently and revalidated cheaply;
an inlined SVG is cached only as part of whatever document contains it. For an icon used on one page, inline
wins. For an icon used across a site, a cached file usually wins after the first visit. Measure before
assuming either way.
Private by design
The conversion runs locally with your browser's FileReader API — no upload, no server, no
temporary storage on someone else's disk. Files you are not allowed to send anywhere are fine here.
Hosts differ on whether they keep the data URI. Embedding a Base64 image in Markdown lists GitHub, Notion, and WordPress. The same step in other languages is in how to convert an image to Base64.
More Base64 converters
Frequently asked questions
Should I Base64-encode or URL-encode an SVG for CSS?
Both work in a CSS data URI. Base64 (what this tool produces) is the most compatible and copy-paste safe. URL-encoding usually yields a slightly smaller string for SVG since it's text, but it's fiddlier to get right — Base64 is the safer default.
What does an SVG Base64 data URI start with?
It starts with data:image/svg+xml;base64, followed by the encoded body. Drop it straight into a CSS background-image or an HTML img src.
Is the conversion private?
Yes. Everything runs in your browser with the FileReader API. The SVG is never uploaded to any server.