SVG to Base64 Converter: Encode SVG as Base64 for CSS and HTML

Convert SVG code to a Base64 string or data URI and compare the size with other encodings.

SVG to Base64 Converter tool

1Add your SVG

Drop your SVG here, or click to browse Or paste SVG code anywhere on the page. Nothing is uploaded.
No file?

2Adjust the options

3Preview and download

Live preview
sample.svg
Input and output codeView, edit and copy the code
Input SVG code
Output

Under the hood

How SVG to Base64 Converter works

An SVG to Base64 converter turns SVG code into a Base64 string you can embed directly in CSS, HTML or JSON. It also shows how much larger Base64 is than the original.

  1. Minify first (optional)

    If enabled, comments, metadata and whitespace are removed before encoding, which shrinks the output.

    Minify pass
  2. <svg …>PHN2ZyB4bWxucz0i…

    Encode to Base64

    The SVG text is converted to UTF-8 bytes and then to Base64, which uses 4 characters for every 3 bytes.

    UTF-8 · btoa
  3. background-image: url("data:image…

    Wrap as you need

    Choose raw output, a CSS background-image rule or an <img> tag, each with the data URI prefix.

    data:image/svg+xml;base64,
  4. SVGURL-encodedBase64

    Compare the sizes

    A chart shows the SVG, URL-encoded and Base64 sizes so you can choose the smallest option.

    Size comparison
The four stages of the SVG to Base64 Converter, from your input to the finished file.

What to know about Base64 SVG

33% overhead
Base64 is always about a third bigger than the source.
Not human-readable
Unlike URL-encoded SVG, Base64 cannot be edited by eye.
Works everywhere
Base64 data URIs work in CSS, HTML, JSON and many tools.

Step by step

SVG to Base64 Converter process

Four steps convert an SVG to Base64. Minifying first keeps the output small.

  1. Add your SVG

    Drop a file, paste code or press the sample button.

    Tip: The sample is a small icon.

    Drop SVG
  2. Choose the wrapper

    Pick Raw, CSS or <img> depending on where you will use it.

    Tip: The output updates immediately.

    EncodingWrapperMinify
  3. Check the sizes

    Look at the Base64 overhead tile.

    Tip: Switch to URL-encoded if smaller.

  4. Copy or download

    Press Copy code to put it on the clipboard, or Download to save it as a text file.

    Tip: Copying from the preview gives the full output.

    Download SVGsvg-to-base64.svg

Use the SVG to Base64 Converter

Reference

SVG to Base64 Converter settings / conversion chart

The table lists where each wrapper is used. The chart compares the encodings.

Relative size by encoding

Relative size by encodingSVG source: 1×; URL-encoded: 1.2×; Base64: 1.33×.SVG source1×URL-encoded1.2×Base641.33×
Base64 is about 33% larger than the source; URL-encoded is usually smaller.

At a glance

  • Largest: Base64.
  • Smallest: SVG source.

Base64 is about 33% larger than the source; URL-encoded is usually smaller.

SVG to Base64 Converter output wrappers
WrapperLooks likeUse it in
Rawdata:image/svg+xml;base64,…Any URL field
CSSbackground-image: url("…");Stylesheets
<img><img src="…" alt="">HTML pages
Minify firstSmaller inputAll of the above

Answers

SVG to Base64 Converter FAQ

Questions people ask about the SVG to Base64 Converter, answered for this specific use case.

Why is the Base64 output larger?

Base64 turns every 3 bytes into 4 characters, so the output is about 33% larger than the SVG.

Is Base64 the best way to embed an SVG?

URL-encoded data URIs are often smaller and compress better. Compare the sizes shown.

Can I use the output in CSS?

Yes. Choose the CSS wrapper to get a ready-to-paste background-image rule.

Does it handle non-English characters?

Yes. The SVG is encoded as UTF-8 before Base64, so special characters are preserved.

Is my SVG uploaded?

No. The encoding happens in your browser.

Ready to try it?

Your result is one drop away.

Open the SVG to Base64 Converter

All converters

Every free converter and SVG tool

43 free tools that run in your browser. Pick a converter below, or search by format or task.