Image To Base64

Encode any image into a base64 string or data URI so it can be embedded directly in HTML, CSS or code. No signup. Ideal for developers embedding small images.

Remove Ads
Remove Ads

Result

Base64 Data URI
Remove Ads

Share on Social Media:

An image to base64 encoder turns a picture into a long text string you can paste straight into HTML, CSS or code — free, with no account. Choose an image and the tool gives you a data URI, ready to use as an image source with no separate file and no extra request. Everything runs in your browser: your image is never uploaded or stored.

On this page

  1. How to Encode an Image to Base64 Step by Step
  2. What Base64 Encoding Does for Images
  3. Embedding Versus Linking an Image
  4. Who Encodes Images to Base64
  5. Pro Tips for Base64 Image Encoding
  6. Common Image to Base64 Mistakes to Avoid
  7. Related Tools You May Need Next
  8. Frequently Asked Questions

How to Encode an Image to Base64 Step by Step

  1. Choose an image. Click the file picker and select one image — PNG, JPEG, GIF or any image type. Encoding starts the moment you choose the file; there is no button to press.
  2. Wait a moment for the data URI. The output appears in the result box, starting with data:image/...;base64, followed by the encoded string.
  3. Copy the encoded string. One click copies the full data URI, ready to paste where an image source goes.
  4. Paste it into your code. Use it as an img src in HTML, a background in CSS, or a value in JSON — the image displays without a separate file or an extra request to fetch it.
  5. Strip the prefix if you need bare base64. The output always includes the data: prefix. Delete everything up to and including the comma if your code wants only the base64 characters.

Flat illustration of an image converting to base64 code text

What Base64 Encoding Does for Images

Base64 encoding represents binary data, such as an image, using only text characters, so that the image can be embedded directly inside text-based formats like HTML, CSS and JSON. Instead of linking to a separate image file, the entire image is included as a long string of safe characters — letters, digits, plus, slash and equals — and travels with the code rather than as a separate file that must be fetched separately.

The output is always a data URI. It has three parts: the prefix data:, the image's MIME type (such as image/png), and the base64 payload after ;base64,. That prefix tells the browser what kind of image the string is, so the whole thing can be used directly as an image source. A worked example — a real 70-byte 1×1 red PNG — encodes to exactly this 118-character data URI:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==

The main cost of embedding an image as base64 is size. Encoding produces a string roughly a third larger than the original binary, since text takes more space than binary: the 70-byte PNG above becomes 96 base64 characters, and a 3,000-byte file becomes exactly 4,000 base64 characters. A 100 KB image therefore becomes roughly 133 KB of text. That is why base64 embedding suits small icons and logos, but not large photos — a large image bloats your code and cannot be cached separately by the browser.

Base64 is lossless. The encoding only changes how the bytes are represented, not the bytes themselves, so decoding the string gives back the exact original image with no quality change. The tool does not convert, resize or recompress anything: a JPEG stays a JPEG, a PNG stays a PNG, and transparency is kept because the bytes are encoded exactly as they are.

No size limit is stated. The tool has no maximum file size in its code, but that is not a reason to encode a 5 MB photo: the result would be a roughly 6.6 MB string pasted into your code. Compress or resize the image first, then encode the small version.

Embedding Versus Linking an Image

AspectBase64 embeddedLinked file
Network requestNone — loads with the codeOne request per image
SizeAbout a third larger than the binaryOriginal binary size
CachingNot cached separately — downloaded again with every page loadBrowser can cache it
File managementTravels with the code, nothing to uploadSeparate file to host and keep in sync
Best forSmall icons and logosLarger images and photos
FormData URI in HTML or CSSA URL in an img src

The trade-off is simple: embedding saves a request but costs size and caching. For a small icon used on every page, that trade is often worth it. For a photograph, it almost never is — link the file instead.

Who Encodes Images to Base64

Front-end developers embedding icons. A developer turns a small logo or icon into a data URI so it loads with the page, with no extra request and no separate file to deploy.

Email developers. An email developer embeds images in the message itself, because many email clients block or strip externally linked images while embedded ones display.

Developers storing images in JSON or data. A developer whose data format carries text, not binary, encodes images so they can travel inside JSON, a database field or an API payload.

Designers prototyping single-file pages. A designer builds a demo or prototype as one self-contained HTML file, with every image embedded, so it can be shared as a single file.

Anyone needing a self-contained file. A person who needs an HTML file that works offline, with no separate images folder, encodes the images into the file itself.

Laptop showing an image converting to a base64 text string with a copy button

Pro Tips for Base64 Image Encoding

Keep it small. Icons and logos are the right candidates. If the image is a photograph, compress it or link it instead of encoding it.

Compress or resize BEFORE encoding. This tool encodes the bytes exactly as they are — it cannot shrink the image. Run the image through our Image Compressor or Image Resizer first, then encode the small version.

Copy the whole string. One missing character breaks the image. Use the Copy button rather than selecting the text by hand, and check the end of the string made it into your code.

Use the MIME prefix as-is for HTML and CSS. The data:image/png;base64, prefix is part of the data URI and must stay. Strip it only when the target specifically wants bare base64 characters.

Test the data URI in a browser. Paste the copied string into a browser address bar: if the image displays, the string is complete and correct.

One file at a time. Choosing a second file replaces the first result, so copy each data URI before encoding the next image.

Common Image to Base64 Mistakes to Avoid

Encoding a large photo and bloating the page. A 1 MB photo becomes about 1.33 MB of text inside your HTML or CSS. Encode small images only; link large ones.

Pasting only part of the string. A truncated data URI shows a broken image with no useful error. Copy the full string with the Copy button and verify the end is there.

Deleting the data: prefix when HTML needs it. An img src needs the full data URI, prefix included. Bare base64 without the prefix will not display as an image.

Keeping the prefix when bare base64 is wanted. The reverse mistake: some APIs and fields want only the base64 characters. Delete everything up to and including the comma in that case.

Expecting the tool to resize, compress or convert the image. It does none of those things. The bytes you choose are the bytes that get encoded, format and size unchanged.

Encoding the same image on many pages instead of linking it once. An embedded image is downloaded again with every page that contains it. If the same icon appears on fifty pages, a linked file is cached once and reused.

Related Tools You May Need Next

Base64 to Image. Turn a base64 string back into a picture.

Base64 Encode Decode. Base64 on text rather than images.

Image Compressor. Shrink an image before encoding it.

Image Resizer. Resize an image before encoding it.

JPG to PNG. Change image formats.

PNG to JPG. Change image formats.

3D illustration of an image converting to encoded text with a copy icon

Frequently Asked Questions

How do I convert an image to base64?

Choose the image in the file picker. Encoding starts immediately — there is no button to press — and the result appears as a data URI in the output box. Copy it with the Copy button and paste it into your HTML, CSS or code.

What is a data URI?

A data URI is a base64 string with a prefix that tells the browser what it is, such as data:image/png;base64, followed by the encoded image. The whole thing can be used directly as an image source, with no separate file.

Why is the base64 string longer than the image file?

Because base64 represents binary data as text, which takes more characters: roughly a third more. A 3,000-byte file becomes exactly 4,000 base64 characters, and a 100 KB image becomes about 133 KB of text.

Does base64 encoding change the image quality?

No. Base64 is lossless — it only changes how the bytes are written down, not the bytes themselves. Decoding the string gives back the exact original image, and the tool does not resize, recompress or convert anything.

Can I encode a JPEG, or only PNG?

Any image type works: PNG, JPEG, GIF and others. The MIME type in the data URI prefix matches the file you chose, and the image keeps its original format — a JPEG stays a JPEG.

Is there a size limit on the image I can encode?

No size limit is stated on the page, and the tool has no maximum in its code. In practice, keep images small: a large image produces a very long string that bloats your code. Compress or resize first.

How do I use the data URI in HTML and CSS?

In HTML, paste the full data URI as the value of an image element's src attribute. In CSS, use it as a background-image url. Keep the prefix in both cases.

How do I get just the base64 without the data: prefix?

Delete everything up to and including the first comma — the data:image/png;base64, part. What remains is the bare base64 string, for APIs and fields that want base64 without a prefix.

Can I encode more than one image at a time?

No. The tool takes one file at a time, and choosing a second file replaces the first result. Copy each data URI before encoding the next image.

Is the image to base64 encoder free?

Yes, it is completely free with no account and no usage limit. It runs entirely in your browser, so your image is never uploaded or stored.