Turn an image into a Base64 data URI you can paste straight into HTML or CSS.
How to use
- Choose an image file.
- Press Convert to Base64.
- Click the box to select the data URI and copy it.
Good to know
Base64 makes data about 33 percent larger, so embed only small icons and logos. Large images are better kept as separate files.
How Do You Convert an Image to Base64 Online?
A free online image to Base64 converter turns a picture file into a long line of text that can be pasted straight into HTML or CSS. This Image to Base64 Converter runs in your browser: choose an image, press Convert to Base64, and the tool shows the file size, the Base64 length in characters, the full data URI and a short HTML example. Nothing is uploaded.
What does the tool do and why is it useful?
Normally a web page points to an image file with an address. A data URI works differently: the image itself is written into the page as text. This removes the need for a separate file request, which can be handy for tiny icons, email templates, single file demos and quick prototypes.
After you choose a file and press the button, the tool displays four things:
- The file size of your image.
- The length of the Base64 text in characters.
- The full data URI in a read-only box. Click the box to select its content.
- A short HTML
imgexample that uses the data URI.
What is Base64 and how does it work?
Base64 is a way to write binary data using only 64 safe text characters: capital letters, small letters, digits, plus and slash, with equals signs as padding. It takes the bytes of the file three at a time (24 bits) and splits them into four groups of 6 bits. Each group becomes one character. So every 3 bytes turn into 4 characters.
The length of the output for a file of n bytes is 4 x ceil(n / 3), where ceil rounds up to a whole number. The result is about one third larger than the original, which is why the size grows by roughly 33 percent. The tool reads your file in the browser and encodes it locally. The data URI starts with a short prefix that names the type, for example data:image/png;base64,, followed by the encoded text.
How do you use the converter step by step?
- Click the file picker and choose an image.
- Press the Convert to Base64 button.
- Read the file size and the Base64 length.
- Click inside the read-only box to select the whole data URI, then copy it with your keyboard or menu.
- Paste it where you need it, or adapt the short HTML example shown by the tool.
Nothing is calculated until the button is pressed. There is no separate copy button, so use selection and your device copy command.
What do worked examples look like?
Example 1: the 3 byte rule
A file of 3 bytes gives 4 x ceil(3 / 3) = 4 characters. A file of 1 byte also gives 4 x ceil(1 / 3) = 4 characters, because the last group is padded with equals signs. A file of 2 bytes gives 4 as well.
Example 2: a 1000 byte icon
A 1000 byte image gives 4 x ceil(1000 / 3) = 4 x 334 = 1336 characters. That is 336 more than the original, an increase of 33.6 percent. Add the prefix data:image/png;base64,, which is 22 characters, and a complete data URI is 1358 characters long.
Example 3: a 2 KB image
A file of 2048 bytes gives 4 x ceil(2048 / 3) = 4 x 683 = 2732 characters. The growth is 684 characters, or 33.4 percent.
Example 4: a 10 KB image
A file of 10240 bytes gives 4 x ceil(10240 / 3) = 4 x 3414 = 13656 characters. The growth is 3416 characters, about 33.4 percent. A 10 KB icon pasted into a page adds more than 13 thousand characters of text.
Example 5: a number that divides evenly
A file of 30000 bytes is divisible by 3, so no padding is needed: 4 x 10000 = 40000 characters. That is exactly one third more, or 33.33 percent.
Example 6: using it in HTML
The short example in the result has this shape, with the long text shortened here:
<img src="data:image/png;base64,iVBORw0KGgo..." alt="icon">
In CSS the same string can sit inside a url() value of a background image. The data URI works in both places.
When should you use Base64 images, and when not?
Use it for small icons, a tiny logo in an email template, or a demo page that must live in a single file. Avoid it for photographs and large graphics. The text is a third larger than the file, it cannot be cached by the browser separately from the page, and it makes HTML or CSS files heavy and hard to read. A real image file is almost always the better choice for anything beyond a few kilobytes.
If an image is too big, make it smaller first with the Image Resizer and reduce the file size with the Image Compressor. A small input gives a small data URI.
Why does the length shown by the tool matter?
The Base64 length in characters is a quick measure of how much text you are about to put into a page. Every character is at least one byte in the final HTML or CSS file, so the figure tells you directly what your file will grow by. A rule of thumb is to compare it with the cost of a normal request: if the image is only a few kilobytes, embedding it can save a round trip. Once the string reaches tens of thousands of characters, the saving disappears and the page simply becomes heavier. The length also helps when a system limits the size of a field, because you can check the number before you paste anything.
What tips give the best results?
- Keep source images under a few kilobytes.
- Prefer PNG or WebP for simple icons, since they stay sharp. Use JPG for tiny photos only.
- Always give the
imgelement a meaningfulalttext. - Check the Base64 length shown by the tool before pasting. If it runs to tens of thousands of characters, reconsider.
- Copy the whole value. Cutting off even a few characters corrupts the picture.
- To encode or decode plain text instead of a file, use the Base64 Encoder and Decoder.
What are the common mistakes?
- Believing Base64 is encryption. It is only a different way to write the same data. Anyone can decode it instantly, so it hides nothing and protects nothing.
- Embedding large photos. This bloats a page and slows it down.
- Copying only part of the string. The image then fails to display.
- Dropping the prefix. Without
data:image/...;base64,a browser does not know what the text is. - Expecting automatic updates. The result appears only after pressing the button.
Who uses an image to Base64 converter?
- Web developers embedding small icons in CSS or HTML.
- Email template builders who want fewer external files.
- Students learning how data URIs and encoding work.
- People creating a single file HTML demo to share.
- Developers testing an API that expects an image as text.
When you minify stylesheets that contain data URIs, the CSS Minifier is a natural next step. Further helpers are collected among our free tools.
Is the converter private?
Yes. The file is read and encoded inside your browser. It is not uploaded, not stored and not sent to any server. No account is required and no history is kept. Be aware that once you paste a data URI into a public page, the image becomes public along with it.
What are the limitations?
- One image at a time.
- Output is a data URI and a short HTML example, with no download and no copy button. Click the read-only box to select the text.
- Base64 output is about 33 percent larger than the file.
- Large images produce extremely long strings that can be slow to handle.
- It does not compress or resize the image. Prepare the file first.
- Nothing appears until you press the button.
Frequently asked questions
What is a data URI?
It is a way to include a file's content directly in HTML or CSS as text, starting with a prefix such as data:image/png;base64,.
Why is Base64 about 33 percent bigger?
Every 3 bytes become 4 characters, so the size grows by a factor of 4 / 3.
Is Base64 a form of encryption?
No. It is an encoding that anyone can reverse. Do not use it to hide information.
How do I copy the result?
Click the read-only box to select its content, then use your normal copy command.
Can I use the result in CSS?
Yes. Place the data URI inside url() for a background image.
Which images are suitable?
Small icons and simple graphics. Photographs and large pictures are better kept as files.
Does the tool compress my image?
No. It encodes the file as it is.
Is my picture uploaded?
No. Everything happens in your browser.
Small images, simple text
For a tiny icon that should travel inside the page itself, press Convert to Base64, copy the data URI and paste it where it belongs. For anything larger, a normal image file wins.
