Guide
When to inline an image as Base64, and when not to
A data URL puts an image directly inside your code, as text, instead of linking to a separate file: data:image/png;base64,iVBORw0KGgo…. It’s useful in a few specific situations and a performance problem in most others. This tool generates the snippets in both directions, and it helps to know when to use them.
Where inlining makes sense
- Tiny icons and logos in CSS or HTML, where a separate file request would cost more than the extra bytes.
- Self-contained files: a single HTML report, a demo or an offline page that must work without any other files.
- JSON and APIs that carry images as text fields, such as an avatar in a configuration or a thumbnail in a test fixture.
- Prototypes and code playgrounds where you can’t upload assets easily.
Where it doesn’t
- Photos and large images. Base64 is about 33% larger than the file, and the tool shows the exact increase. A 200 KB photo becomes roughly 270 KB of text inside your HTML or CSS, which blocks rendering while it downloads.
- Images used on several pages. A normal image file is cached once by the browser and reused. An inlined image is downloaded again inside every page or stylesheet that contains it.
- HTML emails. Several widely used email apps, including Gmail, don’t display data-URL images. Host the image instead.
The tool warns you when an image is over 100 KB, a good rule of thumb for “probably shouldn’t be inlined”.
The snippets
After you drop or paste an image, you get five ready-to-copy versions:
| Output | Example use |
|---|---|
| Data URL | Anywhere a URL is accepted |
| Base64 only | JSON fields, APIs, config files that add the prefix themselves |
| HTML | <img src="data:…" alt="" />. Remember to fill in the alt text |
| CSS | background-image: url("data:…"); for icons in stylesheets |
| Markdown |  for notes and documentation tools that support it |
The image is read byte for byte and isn’t re-compressed, so decoding the data URL gives back exactly the original file. To make the snippet smaller, shrink the image first with the Image Compressor or the Image Resizer.
SVG and ICO
SVG files encode fine, but because SVG is already text, URL-encoding it (escaping characters such as # and <) is often smaller than Base64 in CSS. For a few small icons the difference doesn’t matter. ICO files are accepted too, which is handy for inlining a favicon in a single-file page.
Decoding Base64 back to an image
Switch to Base64 → Image and paste either a full data URL or the bare Base64 text. The tool recognizes PNG, JPEG, GIF, WebP and SVG from the content itself, shows a preview, and offers the file for download. This is useful for debugging: checking what an API actually returned, extracting an image from a JSON fixture, or recovering an icon from an old stylesheet. If the text isn’t valid Base64, you’ll see an error instead of a broken image.
Security notes
Base64 isn’t encryption. Anyone can decode it, so don’t use it to hide anything. When you add data URLs to a site with a Content Security Policy, the policy must allow data: for images (img-src data:). Many strict policies do, but not all.
Everything here runs in your browser, so internal icons and screenshots aren’t uploaded. For text and files rather than images, use the Base64 Encoder.
Who encodes images as Base64
- Front-end developers inline small icons and logos in HTML, CSS or JavaScript to avoid extra requests.
- Email developers test inline images in HTML emails (with care, as many email clients block data URLs).
- API developers send images inside JSON payloads, for example to an image-recognition service.
- Technical writers embed small images directly in Markdown documents that must be a single file.
- Testers create fixtures with embedded images for automated tests.
A complete example: an inline icon in CSS
- Open a small SVG or PNG icon, ideally under 5 KB.
- Copy the CSS snippet, a background-image rule with the data URL.
- Paste it into your stylesheet for the element that shows the icon.
- Check the size line: the Base64 version is about a third larger than the file.
A complete example: checking an image inside an API response
A JSON response contains a long Base64 string under an “image” field. Switch to Base64 → Image, paste the string, and the preview shows the picture; the type (PNG, JPEG and so on) is detected from the data. Download it to inspect it in an image viewer.
When to inline, and when not
| Image | Inline? |
|---|---|
| Tiny icons and simple SVGs | Yes, often worth it |
| Images used on many pages | No, a cached file is better |
| Photos and anything over about 100 KB | No, it bloats HTML and CSS |
Tips
- Base64 is not encryption; anyone can decode the image.
- Prefer SVG for icons; it stays sharp and is usually smaller.
Checked against the current version of the Image to Base64 on .

