Image to Base64 (PNG/JPG/SVG → Data URI)

Private by design — everything runs locally in your browser.

Image & Actions

Drag & drop an image here
…or click to upload / paste from clipboard
No file loaded.

Preview & Details

Filename
MIME type
Image size
File size
Base64 length
Inflation

Tip: You can also press Ctrl/Cmd + V to paste an image from your clipboard.

Why Convert Images to Base64?

Converting images to Base64 isn't about making them smaller or more secure, but rather about embedding them directly into text-based files or data streams. Here are the primary reasons why this conversion is useful:

  • Embedding in HTML/CSS:
    • Reduced HTTP Requests: When an image is linked externally (e.g., ``), the browser makes a separate HTTP request to fetch that image. For many small images, this can add overhead and slow down page loading. Embedding images as Base64 (e.g., `` or in CSS `background-image: url('data:image/png;base64,...')`) eliminates these extra requests, as the image data is part of the HTML/CSS file itself.
    • Offline Access: If a web page is saved for offline viewing, embedded Base64 images are included directly, ensuring they display correctly without needing an internet connection to fetch external resources.
    • Email Signatures/Templates: Many email clients or templates prefer or require images to be embedded directly as Base64 to ensure they display consistently across different email platforms without being blocked or breaking links.
  • Embedding in JSON/XML: When transferring data via APIs or storing configuration, it's often more convenient to include small binary assets like icons directly within the JSON or XML structure as Base64 strings, rather than hosting them separately and sending URLs.
  • Simplifying Data Management: For very small images, it can simplify development and deployment by eliminating the need to manage separate image files. The image data is simply part of the code or document.
  • Security Policy (CSP): In some web security contexts, Content Security Policy (CSP) might restrict external resource loading. Embedding images as Base64 can sometimes bypass these restrictions for internal or small assets.

How to Use a Base64 Image String Later?

Once you have an image converted to a Base64 string, you can use it in various places:

  • In HTML `` tags:
    <img src="data:image/png;
              base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/
              w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Tiny Red Dot">
    Just replace `image/png` with the actual MIME type of your image (e.g., `image/jpeg`, `image/gif`) and paste your Base64 string after `base64,`.
  • In CSS `background-image`:
    .my-element {
      background-image: url('data:image/jpeg;base64,/9j/
      4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQg
      ...your_base64_string_here...');
    }
    Again, ensure the correct MIME type.
  • In JSON/JavaScript:
    const imageData = "data:image/svg+xml;
              base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllc
              l8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwM
              C9zdmciIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwI
              DAgMTkgMTkiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgM
              CAwIDE5IDE5Ij48Y2lyY2xlIGZpbGw9IiMwMDZBQ0MiI
              GN4PSI5LjUiIGN5PSI5LjUiIHI9IjcuMyIvPjwvc3ZnPg==";
    // You can then dynamically set this to an  src or CSS background-image
    The string can be stored as a variable and used programmatically.
  • Embedding in PDFs or other document formats: Many document formats support embedding images directly using Base64 encoding.
  • API Payloads: When an API needs to send a small image along with other data, it can be embedded as a Base64 string in the JSON payload, rather than requiring a separate file upload.

While Base64 offers convenience for embedding, remember the increase in file size. For large images, it's generally more efficient to link to external image files or use other optimization techniques.

Explore more tools