Image to Base64 Converter
Convert images to Base64 strings. Get Data URI, HTML img tag, or CSS background-image output.
Why I Built This Image to Base64 Converter
I was constantly converting images to Base64 for various projects - embedding icons in CSS, creating self-contained HTML emails, and building single-file demos. Every time, I had to either write a quick script or use some sketchy online tool that wanted to track me. So I built this.
The converter runs entirely in your browser. Drag in an image, get Base64 out. No uploads, no accounts, no limitations. I use it almost daily for small icons and logos that I want to inline directly in my code.
What I Use It For
- CSS Icons - Embedding small icons as background-image data URIs
- Email Templates - Inline images that display without external loading
- Single-File HTML - Creating self-contained demos and reports
- Favicons - Converting ICO files for inline use
- SVG Embedding - When I need SVG in a CSS url() but can't use inline SVG
- Quick Previews - Testing how an image looks as embedded data
For text encoding, I use the Base64 Encoder/Decoder which handles strings and files. This tool is specifically optimized for images with preview and multiple output formats.
Understanding Base64 Image Encoding
Base64 converts binary image data into ASCII text. This lets you embed images directly in HTML, CSS, or JavaScript without external file references. The trade-off is size - Base64 increases the data by about 33%.
Output Format Explained
- Raw Base64 - Just the encoded string. Use this when you need to build your own data structure or send the data via API.
- Data URI - The complete
data:image/png;base64,...format. Drop this directly into an img src attribute or CSS url(). - HTML img tag - Ready-to-paste
<img>element with the embedded data. Perfect for quick prototyping. - CSS url() - The
background-imageproperty with data URI. Copy directly into your stylesheet.
When to Embed Images as Base64
Embedding isn't always the right choice. Here's my rule of thumb after years of web development:
- Under 10KB - Almost always embed. The HTTP request overhead isn't worth it.
- 10-50KB - Consider embedding for critical above-the-fold images.
- Over 50KB - Use external URLs. The 33% size increase hurts more than the extra request.
Email templates are the exception - I embed everything because email clients block external images by default. Users see my images immediately without clicking "load images".
Practical Examples
CSS Background Icons
For small UI icons, I often embed them directly in CSS. This eliminates icon loading flash and reduces HTTP requests. The CSS output format gives you exactly what you need:
.icon-check {
background-image: url('data:image/svg+xml;base64,...');
background-size: contain;
width: 24px;
height: 24px;
}Inline Favicons
You can even embed favicons directly in your HTML head. Useful for single-file HTML applications or when you want the favicon to load instantly:
<link rel="icon" href="data:image/x-icon;base64,..." />JavaScript Image Data
Sometimes I need to include images in JavaScript bundles for offline-capable apps. The raw Base64 output works great for this:
const logoBase64 = 'iVBORw0KGgoAAAANSUhEUgAA...';
const logoUrl = `data:image/png;base64,${logoBase64}`;Tips From Experience
- Optimize images first - Run PNGs through a compressor before converting. Smaller input = smaller Base64.
- Consider WebP - Modern browsers support WebP, which compresses better than PNG or JPEG. The resulting Base64 will be smaller.
- SVG for icons - Vector graphics compress incredibly well as Base64. A typical icon might be just a few hundred bytes.
- Watch your bundle size - Embedding images in CSS or JS increases those file sizes. Use build tools to track the impact.
Related Articles
Frequently Asked Questions
Is my image data secure?
Absolutely. Everything happens in your browser using the JavaScript FileReader API. Your images never leave your computer. I use this tool with client assets and confidential mockups all the time.
What's the maximum file size?
The tool accepts images up to 5MB. That said, if you're converting something that large to Base64, you should probably reconsider your approach. Large Base64 strings are unwieldy and hurt performance.
Why does my Base64 output look different from other tools?
Base64 encoding is standardized, so the actual encoded data should be identical. The difference might be in line breaks (some tools add them every 76 characters) or padding. This tool outputs continuous strings without line breaks.
Can I decode Base64 back to an image?
Yes! Use the Base64 Encoder/Decoder tool in decode mode. Paste your Base64 string and it will display the image.
Why doesn't my ICO file work in all browsers?
ICO support varies. The tool converts ICO files correctly, but some browsers don't render ICO data URIs. For maximum compatibility, convert favicons to PNG first.