Sometimes you want an image without a separate image file: a small icon baked into a stylesheet, a logo inside a one-file HTML report, a test image in a JSON fixture. A data URI does exactly that. It is the whole image written as text, which the browser decodes and displays like any other image.
Choosing a snippet
- Data URI — the complete
data:image/png;base64,…value. Use it anywhere a URL is accepted. - HTML — a ready
<img>tag with your alt text. - CSS — a
background-image: url(…)line for stylesheets. - Markdown —
for README files and documentation tools that allow it. - Base64 only — the raw string, for JSON APIs and databases that store the type separately.
Keep it for small images
Base64 adds about a third to the size, and embedded images can’t be cached on their own. That’s a good trade for a 2 KB icon. It’s a poor one for a 200 KB photo, which also makes your HTML or CSS slower to download and parse. The tool warns you above 10 KB.
For SVG, consider not using Base64
SVG is already text. In CSS, a URL-encoded SVG data URI is usually smaller than Base64. The SVG optimizer can copy one for you.
Everything is encoded locally; your image stays on your device.
How to use the Image to Base64 Encoder
- Drop an image on the box, or click to choose it. PNG, JPG, GIF, WebP, SVG and ICO all work.
- Optionally enter alt text for the HTML and Markdown versions.
- Copy the snippet you need: data URI, HTML
<img>, CSS background, Markdown or plain Base64.
Features
- Five ready-made outputs: data URI, HTML, CSS, Markdown and raw Base64.
- Detects the file type and builds the correct data URI prefix.
- Shows original and Base64 size, and warns when embedding is likely slower.
- Copies the full string even when the on-screen preview is shortened.
- Encoded on your device; the image isn’t uploaded.
Frequently asked questions
Why use Base64 images?
Embedding saves a separate HTTP request and keeps a file self-contained. It is handy for tiny icons in CSS, HTML emails, single-file reports and test fixtures.
How much bigger does Base64 make an image?
About 33% larger, because every 3 bytes become 4 text characters. A 6 KB icon becomes about 8 KB of text.
When should I not use Base64?
For anything larger than roughly 10 KB, or images used on many pages. Normal image files can be cached by the browser and loaded in parallel; embedded ones are downloaded again with every page or stylesheet.
Do Base64 images work in emails?
Support is mixed. Apple Mail and many mobile apps show them, but Gmail and Outlook often block data URI images. For email, attach the image or host it instead.
Written by Dewan Razib