rankato

SVG → data URI in one paste

Get a data URI you can drop straight into an HTML img src, a CSS background-image, or a JS string. Choose base64 or URL-encoded — the tool tells you which is smaller for your file.

URL-encodedsmaller146 bytes
Base64178 bytes
Ready-to-paste snippets
HTML
CSS
JS

Data URIs eliminate the HTTP request cost of tiny images — critical for above-the-fold icons, decorative flourishes, and CSS backgrounds where a network round-trip would delay the first paint. SVGs are especially well-suited to data URIs because SVG is text and can be URL-encoded (which is smaller than base64 for most files). The Rankato SVG-to-Base64 tool produces both encodings side by side, tells you which is smaller for your specific SVG, and generates ready-to-paste HTML, CSS, and JS snippets.

Data URIs vs. external files — when to inline

Every external <img> or CSS background costs a network request, TCP setup, TLS handshake, and file transfer. For images under ~2 KB, the overhead of a network request often exceeds the size of the image itself. Data URIs inline the image into the HTML or CSS, eliminating that overhead — the image is available the moment its host is parsed. The tradeoff is that data-URI images can't be cached separately, so they add to every HTML/CSS bundle download. The sweet spot: inline anything under 2 KB, ship anything over 4 KB as a separate file.

Base64 vs. URL-encoded — which is smaller?

SVG is text, and text URL-encoded is smaller than the same text base64-encoded (base64 adds 33% overhead). For a typical logo, URL-encoded is 20–25% smaller than base64. The tool shows both sizes so you can pick, but URL-encoded is the right default for SVGs. For binary formats (PNG, JPEG) base64 is the only option since they contain bytes URL-encoding can't shorten.

HTML, CSS, and JS snippets

Every conversion produces three copy-ready snippets: an HTML <img src="data:image/svg+xml,…">, a CSS background-image: url('data:image/svg+xml,…'), and a JS string literal for use in JSX, template strings, or a JSON config. Each snippet has its own copy button and a size counter (how many bytes it will add to your bundle).

Auto-minification before encoding

Whitespace, comments, and editor cruft inflate the data URI. Toggle Auto-minify before encoding (on by default) to run the SVG through a whitespace-only minifier before generating the URI. Typical savings: 20–30% for design-tool exports, 5–10% for already-tidy SVGs.

Batch mode with lookup table

Drop multiple SVGs and get a JSON lookup table: { "icon-check": "data:image/svg+xml,…", "icon-close": "…" }. Paste that into a JS module and reference by key — a common pattern for icon sets embedded in code rather than shipped as separate assets.

Tool FAQs

Everything you need to know about using SVG to Base64 Data URI.

Should I always inline my SVGs?+

No. For SVGs used on multiple pages, an external file lets the browser cache it once and reuse everywhere. For a page-specific hero, above-the-fold icon, or CSS decoration where saving an HTTP request improves LCP, inline. Under 2 KB, inline; over 4 KB, external; between, measure.

Why doesn't my CSS data URI work?+

Two common causes: (1) You used double quotes inside the URL when the CSS url() is also using double quotes — wrap in single quotes instead. (2) You forgot to URL-encode # characters — they terminate the URL prematurely. The tool handles both automatically.

Does data URI hurt performance?+

For large images, yes — data URIs can't be cached separately from their host, so if a 100 KB PNG is inlined into every HTML page it adds 100 KB to every page load. For small images (<4 KB), the network savings outweigh the caching loss.

Can I include a data URI in an email?+

Most modern email clients allow data URIs. Outlook (all versions) blocks them for security — for guaranteed Outlook rendering, host the image externally.

What's the max size of a data URI?+

Depends on the context. Browsers accept up to ~2 MB in an <img>. CSS url() in Firefox and Chrome accepts effectively unlimited size, but performance degrades above 100 KB. For SVGs, if your file exceeds 20 KB you're likely better off with an external .svg file.