Online bidirectional converter between images and Base64 strings, supporting all formats including JPG/PNG/GIF/WebP/BMP/AVIF. One-click generation of HTML/CSS/Markdown embedding code. Local browser processing ensures your privacy and security.
Supports JPG, JPEG, PNG, GIF, BMP, WebP, AVIF, SVG formats, max 50MB per file
Instantly outputs Base64 encoding after uploading an image, no need to wait for server response. Local Canvas rendering delivers 10x faster speed.
All conversions are done in your browser. Image files never leave your device — 100% secure for sensitive files and commercial assets.
Provides four code formats: raw Base64, HTML img tag, CSS background, and Markdown. Copy and paste directly into your projects.
Covers all mainstream formats including JPEG, PNG (with transparency), GIF, WebP, BMP, AVIF, SVG, HEIC. Max file size 50MB.
Displays key parameters like original dimensions, raw size, encoded size, and size expansion ratio to help you decide whether to embed.
Perfectly adapted for Windows, macOS, Linux desktops, iOS/Android mobile devices, and tablets with responsive design.
Click the upload area to open the file browser, or directly drag a local image into the dashed box. Processes single images up to 50MB.
Choose the output format as needed (keep original / JPG / PNG / WebP), and adjust compression quality. WebP is recommended for the smallest size at equivalent quality.
Choose based on your use case: raw Base64 string, HTML img tag (for web pages), CSS background (for stylesheets), or Markdown (for docs/notes).
Click "Copy Code" to paste directly into your project, or download as a TXT file for backup. Reverse operation: paste Base64 to instantly restore and download the image.
Base64 is an encoding scheme that represents arbitrary binary data using 64 printable ASCII characters (A-Z, a-z, 0-9, +, /). During encoding, every 3 bytes (24 bits) of binary data are split into 4 groups of 6 bits, each mapped to one Base64 character, with = padding for incomplete groups. For example, converting the binary pixel data of a PNG image into a plain text string allows it to be directly embedded in text formats like HTML, CSS, JSON, and XML without requiring separate image files.
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABmJLR0QA/wD/AP+gvaeTAAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TpSIVduwg...
Converting hundreds of KB or even several MB large images to Base64 and writing them into HTML/CSS not only bloats files by 33% but also blocks HTML/CSS parsing, drastically increasing first-screen white-screen time.
✅ Correct: Only embed icons ≤ 10KB; use independent CDN URLs + lazy loading for large images.
Directly pasting a raw Base64 string into img src causes broken images since the browser cannot identify the format.
✅ Correct: Use the standard format data:image/jpeg;base64,{encoding}, or check the "Include Data URI prefix" option in this tool.
Forcing photo-style JPG images to output as PNG not only multiplies their size but delivers zero quality improvement.
✅ Correct: Use JPG/WebP for photographs; PNG for icons/screenshots with transparency; WebP when you need the highest compression ratio.
Inserting line breaks or spaces into Base64 for code aesthetics causes parsing failures in some older browsers.
✅ Correct: Keep Base64 as a single continuous line; if wrapping is needed in CSS, escape line breaks with a backslash \.
Base64 encoding converts every 3 bytes of binary data into 4 ASCII characters, resulting in a file size increase of approximately 33.3%. For example: a 100KB image becomes roughly 133KB after encoding, and a 1MB image becomes about 1.33MB. It is recommended to use the Base64 embedding method only for small icons and thumbnails under 10KB; large images are better served with independent URLs combined with browser caching.
Absolutely secure, nothing is uploaded. This tool is implemented entirely based on HTML5 standard FileReader and Canvas APIs. All file reading, encoding conversion, and image decoding operations are performed locally in your browser's sandbox, and the binary data of image files never generates any network upload requests. You can verify this in your browser DevTools → Network panel: there are no XHR/Fetch requests during the entire conversion process. Business confidential images, personal photos, and screenshots containing sensitive information can all be used with complete confidence.
✅ Advantages: (1) Reduces HTTP requests, accelerates small icon loading; (2) Avoids issues like broken image paths, CORS, and anti-hotlinking; (3) Facilitates packaging single-file HTML/CSS for distribution and offline viewing; (4) Images display directly in emails without downloading attachments.
❌ Disadvantages: (1) 33% larger size wastes bandwidth and traffic; (2) Cannot leverage browser image caching (CSS/HTML re-downloaded with every modification); (3) Increases CSS/HTML file size, blocking the critical rendering path; (4) Not supported in IE8 and older browsers; (5) Poor code readability, bloated source files.
Best Practice: A single image ≤ 8KB reused site-wide → use Base64 embedding; otherwise use independent image URLs + CDN acceleration.
✅ Browser Compatibility: Chrome 4+, Firefox 3.6+, Safari 5+, all Edge versions, Opera 11.5+; IE 8 supports Base64 up to 32KB, IE 9+ has no limit. Mobile iOS Safari 4.2+, Android 2.3+ fully supported.
📐 Practical Size Limits: Browsers themselves have no hard limits, but it is recommended that a single Base64 embedded image does not exceed 200KB, otherwise page loading speed will be severely impacted. Using independent URLs is the more reliable approach for images over 1MB.
Troubleshoot 90%+ of issues in this order:
1️⃣ Check for Whitespace: Remove all line breaks, spaces, and tabs from the Base64 string, leaving only continuous A-Za-z0-9+/= characters. Some websites auto-insert line breaks when copying code.
2️⃣ Check Prefix Completeness: Ensure the format is data:image/CORRECT-FORMAT;base64,. Common mistake: writing png as jpg causes PNG image decoding to fail.
3️⃣ Check for Missing Characters: Base64 character count must be a multiple of 4, with 0-2 trailing = padding characters. One missing character at the end will break the entire image decode.
4️⃣ Verify Source Integrity: Confirm the Base64 source is a complete image file, not just a partial fragment. You can use this tool's reverse decode first, then re-encode and compare.