Image to Base64 and SVG to Data URI
Base64 turns an image's bytes into text so it can sit inside HTML or CSS as a data URI, for example src="data:image/png;base64,...". The text is about a third larger than the file. Drop an image below to get the data URI, ready-made img and CSS snippets, and advice on whether inlining it is worth it.
| Image | Inline it? | Why |
|---|---|---|
| Icon under 4 kB | Usually yes | Saves a request at little cost |
| SVG logo or icon | Yes, URL-encoded | Smaller than Base64 and still readable |
| Above-the-fold image, 4 to 20 kB | Sometimes | Only if it appears on one page |
| Photo or anything over 20 kB | No | Bloats every load and cannot be cached alone |
Updated
Drop one image or several. Each gets its Base64 data URI and, for SVG files, a URL-encoded version that is usually smaller. Copy any of them as an img tag, a CSS background or a JSON value. Files never leave your device.
How a data URI is built
A data URI has three parts: the data: scheme, the media type such as image/png, and the content. For binary images the content is Base64 and the type is followed by ;base64. For text formats like SVG, the content can be the markup itself with a handful of characters percent-encoded.
Browsers treat a data URI like any other image source. It decodes in memory, so there is no extra request, but there is also no separate cache entry: the image is downloaded again every time the page or stylesheet holding it is.
Better options for most images
For anything bigger than an icon, a normal file served over HTTP/2 or HTTP/3 is almost always faster. Several requests share one connection, the image is cached on its own, and the browser can load it lazily or at the right size with srcset.
Inlining still earns its place for tiny icons in a single component, for placeholders shown while a real image loads, and for self-contained HTML files such as reports or offline demos.
How it works
- Drop images on the box or click to choose them. PNG, JPG, WebP, GIF, AVIF, ICO and SVG all work.
- The browser reads each file locally and encodes it. Nothing is uploaded.
- Compare the original size with the encoded size and read the verdict on whether to inline it.
- Copy the format you need: raw data URI, img tag, CSS background-image or JSON.
Tips
- Compress first, then encode. Encoding a 300 kB photo gives you about 400 kB of text, which is worse than the file you started with.
- For SVG, the URL-encoded form skips Base64 entirely. It is usually smaller and you can still read and edit the markup.
- Data URIs in CSS are downloaded with the stylesheet, which blocks rendering. Keep them to small icons that every page needs.
- Remember the alt text. An inlined image still needs a description for screen readers, or alt="" if it is decorative.
Frequently asked questions
Why is the Base64 version bigger than my image?
Base64 uses four text characters for every three bytes, so the output is about 33% larger, plus a few bytes of padding and the data: prefix. Gzip or Brotli compression on the page claws some of that back, but rarely all of it.
Should I use Base64 for SVG?
Usually not. SVG is already text, so it can go in a data URI with only a few characters escaped. That version is typically smaller than Base64 and stays readable. Use Base64 only if a tool you are pasting into rejects the URL-encoded form.
Do data URIs work in emails?
Support is patchy. Several major email clients block or strip data URI images, so for newsletters host the image and link to it, or attach it with a content ID.
Is there a size limit for data URIs?
Current browsers accept very long data URIs in img tags and CSS, far beyond any sensible image. The practical limit is performance: large inline images slow down the file that contains them. Some older tools and email clients do cut them off.
Related: Base64 text encoder and decoder, Image compressor, SVG viewer and editor, File size converter, HTML images guide.
Start a 7-day free trial or see all free tools. On We.Inc you get a 7-day free trial, not a free plan: card needed, $0 today, cancel before it ends and you pay nothing. AI building is on paid plans from $20 a month.
More in Free Tools
- Invoice Due Date Calculator
- Invoice Generator | Free Tool
- Invoice Late Fee Calculator
- IP WHOIS Lookup
- JavaScript Formatter
- JavaScript Minifier
- JSON Diff Checker
- JSON Formatter and Validator
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App