Image to Base64
Convert an image to a Base64 data URI and copy it as an img tag, CSS background, Markdown or JSON string.
About this tool
A data URI puts an image directly inside HTML, CSS, JSON or Markdown as text, so no separate file has to be hosted or requested. That is handy for small icons in a stylesheet, images in a single-file HTML report, placeholders in a component library or test fixtures in code.
This tool turns an image into a Base64 data URI and gives it to you ready to paste: as a bare URI, an <img> tag with width and height, a CSS background, Markdown or a JSON string. It can also shrink the image to WebP or a smaller size before encoding, and for SVG it offers URL encoding, which is usually shorter than Base64. Everything runs locally in your browser.
How to use Image to Base64
- Choose or drop an image: PNG, JPG, GIF, WebP, AVIF or SVG.
- Keep the original file, or choose Smaller WebP or PNG and a longest side to reduce the size first.
- For SVG files, choose URL-encoded (smaller, readable) or Base64.
- Pick the output format: Data URI, HTML <img>, CSS, Markdown or JSON.
- Copy the result or download it as a text file.
Examples
A small PNG icon
1,234-byte PNG
1,670-character data URI: 22 for data:image/png;base64, plus 1,648 Base64 characters
Base64 writes every 3 bytes as 4 characters, so it is about a third larger than the file.
An SVG checkmark
138-byte SVG
URL-encoded: 171 characters (data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' …); Base64: 210 characters
A CSS background
logo.png, 32 × 32 px, output CSS
.icon { background-image: url("data:image/png;base64,…"); background-size: contain; width: 32px; height: 32px; } When inlining helps, and when it hurts
Inlining saves a request, which helps for a handful of tiny images that appear on first paint, such as icons and logos under a few kilobytes. It also makes a file self-contained: an HTML report or email template with data URIs still shows its images when it is opened offline or forwarded.
The cost is size and caching. Base64 adds about 33% to every image, the browser cannot cache the image separately from the page or stylesheet that contains it, and a large data URI delays everything that comes after it in the file. As a rule of thumb, keep inlined images below a few kilobytes and serve everything larger as normal files. The tool warns you above 20 KB.
Things to check before you paste
- Content Security Policy: if your site sends a CSP header, img-src must allow data: for inline images to load.
- Email: several popular email clients do not display data URI images; for newsletters, use hosted images instead.
- Accessibility: an <img> still needs meaningful alt text. The tool suggests one from the file name; edit it to describe the image.
- SVG from other people can contain scripts. Run it through the SVG optimizer with scripts removed before inlining it.
Frequently asked questions
Everything you need to know about this tool and data security.
Is my image uploaded?
No. The file is read and encoded in your browser, and the result is created on your device.
Why is the data URI bigger than the image?
Base64 uses 4 text characters for every 3 bytes, which adds about 33%, plus a short prefix with the file type. Use Smaller WebP or a smaller longest side to reduce the result.
What is the difference between Base64 and URL encoding for SVG?
SVG is already text, so it can be placed in a URI with only a few characters escaped. That is often around 20% shorter than Base64, and you can still read and edit the markup.
How do I turn a Base64 string back into an image?
Use the Base64 encoder/decoder tool: paste the string or data URI, and it shows the image and lets you download it as a file.
Is there a size limit?
Files up to 10 MB are accepted. Very long results are shortened on screen to keep the page fast, but Copy and Download always include the full text.
Is my data safe when using this tool?
Yes, 100% safe. This tool operates entirely inside your web browser using client-side JavaScript and WebAssembly. Your data never touches any external server.
Related Tools
Encode text to Base64 or decode Base64 to UTF-8 text with instant live conversion.
Shrink SVG files by removing editor data, comments and excess precision, with a before-and-after preview.
Compress JPEG, PNG, and WebP images client-side while preserving visual clarity.
Featured Projects tech-fun.net
Explore more AI & productivity tools
Nihongo GameBox
Master Japanese typing, Kana, and JLPT N5–N1 vocabulary through interactive retro arcade games.
ResumeGPT
Tailors CVs and cover letters to every job opportunity with a multi-agent LLM pipeline, job tracking, and scheduled discovery.
CollectMind
Turns your bookmarks into a searchable AI knowledge base — entirely on-device, powered by Chrome's built-in Gemini Nano.