An image to Base64 converter turns a picture into text you can paste straight into code. Choose a PNG, JPG, GIF, WebP, SVG or ICO file, and this image to Base64 tool encodes it as a data URL, ready-made HTML img tag, CSS background rule, Markdown image or plain Base64 string. Copy the format you need with one click. The image is encoded in your browser and never uploaded.
What a data URL is
Data URLs are URLs that start with data: and let you embed small files inline in documents. They were formerly known as data URIs. A data URL has three parts after the scheme: the media type, such as image/png; the word ;base64 to say the data is Base64-encoded; and the data itself, after a comma. For example, data:image/png;base64, followed by the encoded image. You can use one anywhere a URL to an image would go: an img tag's src, a CSS background-image, or a Markdown image.
What Base64 does
Base64 is a group of binary-to-text encoding schemes that represent binary data as an ASCII string. Because it uses only characters that are safe in URLs, binary data such as an image can be placed inside a data URL. Base64 uses the + and / characters, which can have special meanings in URLs, but because data URLs have no path or query parameters, it's safe in this context. Every 3 bytes of the image become 4 characters of text, so the encoded image is about a third larger than the original file.
Output formats
- Data URL: the complete data:image/…;base64,… string.
- Base64 only: just the encoded data, for APIs or JSON fields that ask for Base64.
- HTML <img>: an img tag with the data URL as its src and the file name as alt text, which you can edit.
- CSS background: a background-image rule with the data URL.
- Markdown: an image link with the data URL.
When to use Base64 images
Embedding an image saves a separate download, which can help for small icons, logos in an email signature, single-file HTML pages and test fixtures. For larger images it's usually better to keep a normal image file: the encoded text is bigger, it can't be cached separately from the page or stylesheet, and it makes your code harder to read. The tool warns you when an image is over 100 KB.
Size limits
Browsers aren't required to support any particular maximum length for data URLs. MDN notes that Chromium and Firefox limit data URLs to 512 MB and Safari to 2,048 MB, so browsers can handle large ones, but long strings still slow down editing, page loading and version control. This tool accepts images up to 10 MB.
How to use the image to Base64 tool
- Choose an image or drop it on the box.
- Pick the output: data URL, Base64 only, HTML, CSS or Markdown.
- Check the preview and the size details.
- Press Copy and paste the result into your code.
Is it private?
Yes. The image is read and encoded by your own browser. It isn't uploaded to a server, so it stays on your device.
Using the snippets
- In HTML, paste the img tag where the image should appear, and change the alt text to describe the picture.
- In CSS, paste the background-image rule inside a selector, and set a width and height so the element shows the image.
- In Markdown, paste the image link where you want it; note that some Markdown viewers don't display data URLs.
- In JSON or an API, use Base64 only when the field expects the raw data without the data: prefix.
- In an email signature, a small logo as a data URL avoids a separate image file, though some email programs block embedded images.
SVG images
SVG files are text, so they can also be embedded without Base64. Base64 still works for SVG and avoids having to escape quotes and special characters, which is why this tool encodes them the same way as other images. The media type for SVG is image/svg+xml.
Decoding again
To turn Base64 back into an image, paste the data URL into your browser's address bar, or decode the Base64 text with a Base64 decoder and save the result with the right file extension. The image is unchanged by encoding and decoding: Base64 is a lossless way of writing the same bytes as text.
Choosing images to embed
Small, simple images work best: icons, small logos, bullets and tiny background patterns. Compress the image first if you can, because every byte saved is about a third more saved in the encoded text. Vector icons as SVG are often the smallest of all.
Common mistakes
- Missing the comma before the data when writing a data URL by hand.
- Typos in ;base64, which browsers ignore without showing an error.
- Embedding large photos, which bloats pages and stylesheets.
- Forgetting alt text in the HTML snippet.
What next
Use this often? Add Image to Bas to your Home screen.
Frequently asked questions
How does the image to Base64 tool work?
Your browser reads the image file and encodes its bytes as Base64, then wraps them in a data URL and HTML, CSS or Markdown snippets.
What is a data URL?
A URL that starts with data:, then the media type, ;base64 and the encoded data after a comma, so a file can be embedded inline.
Why is the Base64 text bigger than the image?
Base64 turns every 3 bytes into 4 characters, so the encoded image is about a third larger.
When should I use Base64 images?
For small images such as icons or email logos. Larger images are usually better as normal files.
Is my image uploaded?
No. It's encoded in your browser and never leaves your device.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.