SVG to Base64 Converter
Turn SVG code or files into a Base64 or URL-encoded data URI, with CSS background and HTML img snippets and the size of each. In your browser.
Inlining a small SVG icon as a data URI saves an HTTP request and keeps a stylesheet or component self-contained. This tool turns an SVG file or pasted SVG code into both kinds of data URI — URL-encoded, which keeps the markup readable and is usually smaller, and Base64 — with ready-to-paste CSS background-image and HTML img snippets and the size of each. It checks that the code really is an SVG and adds a missing xmlns, without which a data URI does not display.
How to use this tool
- Drop .svg files or paste the SVG code.
- Keep "Light minify" on to drop the XML declaration, comments and extra whitespace.
- Choose which data URI the CSS and HTML snippets use.
- Copy the result you need; the sizes show which form is shorter.
Formula
URL-encoded: data:image/svg+xml, + the SVG with " changed to ' (when the SVG contains no '), and only %, #, <, >, {, }, &, ", \, ^, `, |, control and non-ASCII characters percent-encoded (UTF-8). Base64: data:image/svg+xml;base64, + Base64 of the UTF-8 bytes, 4 characters per 3 bytes.
Browsers accept unescaped spaces, quotes of the other kind, = and / inside a quoted url("…") or src="…", which is why URL-encoding only what is required stays short. A # must always be escaped (it would start a fragment), as must %. Minifying keeps a single space inside text, so <text> content is not changed.
Example
The 163-byte test SVG becomes a 202-character URL-encoded data URI (each of its two # becomes %23 and its seven < and > become %3C or %3E) but a 246-character Base64 data URI: 4 × ⌈163 ÷ 3⌉ = 220 Base64 characters plus the 26-character prefix.
Frequently asked questions
Base64 or URL-encoded — which should I use?
URL-encoded is usually smaller and compresses better with gzip, and you can still read it. Use Base64 when a tool insists on it, or in srcset, where spaces are not allowed.
Why did my data URI not show?
Usually because the SVG lacks xmlns="http://www.w3.org/2000/svg", which this tool adds, or because a # was not escaped. External images or fonts referenced by the SVG are never loaded inside a data URI.
Can I change the icon colour from CSS?
Not with background-image: the SVG is a separate image. Edit the fill in the SVG before encoding, or use CSS mask-image with the same data URI and set background-color.
Is my SVG uploaded?
No. Encoding happens in your browser.
Last updated:
Page address with these inputs: https://kakao.mobile/tools/svg-to-base64-tool/
Cite or embed this tool
kakaoCalc. (2026, November 8). SVG to Base64 Converter. https://kakao.mobile/tools/svg-to-base64-tool/
“SVG to Base64 Converter.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/svg-to-base64-tool/.