2 min read
How to Convert an Image to Base64
Learn what a Base64 image is, when to inline one, and how to convert an image to a Base64 data URI for HTML, CSS, or JSON.
What a Base64 Image Is
Base64 encoding turns binary data, like an image, into a string of plain text. When you wrap that string in a data URI, you get something you can paste directly into your code as if it were the image itself — no separate file needed.
This is handy for small assets. A tiny icon inlined as Base64 loads with the page instead of triggering its own network request, and a self-contained HTML email can carry its images inside the markup rather than linking out to them.
When to Inline and When Not To
Inlining shines for small, frequently used graphics — UI icons, a logo in an email, a background texture in CSS. It removes a request and keeps everything in one file.
It works against you for large images. Base64 makes the data about a third bigger, and inlined images can't be cached separately or loaded lazily, so a big photo bloats your HTML or CSS and slows the first load. For anything sizable, a normal image file is better.
Converting Step by Step
The encoder gives you the string in whichever form your code needs.
- 1Open the Image to Base64 Encoder.
- 2Drop an image in, or click to choose one.
- 3Review the preview and the size comparison.
- 4Pick a format: data URI, raw Base64, HTML img tag, CSS rule, or JSON.
- 5Click Copy and paste it into your file.
Understanding the Size Overhead
Base64 represents every three bytes of binary as four text characters, which is where the roughly 33 percent size increase comes from. The tool shows the original and encoded sizes side by side so you can judge whether inlining is worth it.
As a rule of thumb, inline assets under a few kilobytes and leave larger ones as files. The conversion itself happens locally with the browser's FileReader API, so your image is never uploaded while you decide.
Frequently asked questions
When should I use a Base64 image instead of a file?
Inline small, often-used graphics like icons or an email logo to avoid an extra request. For larger images, a normal file is better because Base64 adds about a third to the size and can't be cached separately.
Why is the Base64 string bigger than the image?
Base64 encodes three bytes of data as four text characters, so it's roughly 33 percent larger than the original binary. The encoder shows the exact difference so you can decide whether inlining is worthwhile.
Can I use the result in CSS?
Yes. Choose the CSS format for a ready-to-paste background-image rule, or the HTML format for an img tag. The data URI and raw options cover JSON and other uses.
Tools mentioned in this guide
Image to Base64 Encoder
Convert an image to a Base64 data URI for embedding in HTML, CSS, or JSON — with copy-ready formats.
Developer Tools
Image Converter
Convert images between WebP, JPEG, and PNG in batches — with size comparison.
Image Tools
Favicon Generator
Make a complete favicon pack — .ico plus PNG sizes — from text, emoji, or an image.
Generators
CSS Gradient Generator
Build a linear or radial CSS gradient visually and copy the ready-to-paste code.
Developer Tools
Keep reading