Fixing Broken Base64 Images and Oversized Data URIs
Why a Base64 image shows as broken or fails to decode, how to find the damaged part of a string, and what to do when inlined images slow a page.
Primary Browser Tool
Image to Base64 Converter
Encode images as Base64 data URIs with ready-to-paste HTML, CSS, and Markdown snippets, or decode a Base64 string back into an image file.
When the Image Does Not Display
Paste the string into the Base64 → Image tab. The error message, or the lack of one, narrows down the cause.
| What happens | Likely cause | Fix |
|---|---|---|
| “Characters that are not valid Base64” | Quotes, commas, or other code copied with the string | Copy only the encoded text, from after the comma to before the closing quote |
| “Damaged or cut off” | The string was truncated by a log, a terminal, or a field length limit | Get the complete value from the source |
| “Not a recognized image” | The data is something else (a PDF, a font, JSON) | Check where the string came from |
| Decodes, but the preview fails | The image data itself is incomplete | Re-export from the source |
| Works here, broken on the page | Missing “data:…;base64,” prefix, or a security policy blocking data URIs | Add the prefix; check the Content-Security-Policy img-src rule |
Spotting Truncation
A complete Base64 string has a length that is a multiple of four once padding is counted. Strings cut off mid-way usually fail that test, and even when they pass, the decoded image shows only its top portion followed by gray or garbage. Common culprits are database columns with a length limit, logging tools that abbreviate long values, and copying from a terminal that wraps or clips output.
When Inlined Images Slow the Page
If a page or stylesheet has grown heavy with data URIs, the remedy is to move the large ones back out.
- Decode each large data URI here and save it as a normal file.
- Compress and resize the file, then reference it by URL so the browser can cache it.
- Keep inlining only for images of a few kilobytes that are needed for the first render.
- For repeated icons, an SVG sprite or icon font is more efficient than many separate data URIs.
Practical Examples
Half an image
A profile photo stored in a 65,535-character database column decodes to an image whose lower half is gray. The column limit had cut the string; changing the column type and re-saving fixed it.
Common Mistakes & Honest Limitations
Mistakes to Avoid
- Repeatedly re-encoding the same file hoping for a different result when the problem is in how the string is stored or pasted.
Technical Limitations
- A truncated string cannot be repaired. The missing bytes have to come from the original source.