Image to Base64

Convert an image to Base64 online: get a data URI, raw Base64 string and HTML img tag from any PNG, JPG, WebP, GIF or SVG, encoded in your browser.

Runs in your browser. Files never leave your device.
🔤

Upload Image to Convert to Base64

Converts PNG, JPG, WebP, SVG, GIF into Data URI Base64 text string

About the Image to Base64

Convert an image to Base64 text you can paste straight into code. Choose a PNG, JPG, WebP, GIF or SVG and the encoder gives you the file in three forms: a complete data URI for HTML and CSS, the raw Base64 string for JSON and APIs, and a ready-made <img> tag. That covers most cases where an image has to travel as a string instead of as a separate file.

Each output has its own copy button, so you take exactly the form your code expects. Encoding happens locally with the browser's own FileReader, so the picture never leaves your computer or phone. The bytes are encoded exactly as they are, with no resizing or re-compression, so the quality doesn't change.

How the image to Base64 encoder works

The browser reads the file you pick with its built-in FileReader and returns it as a data URI. That string has two parts separated by a comma: a header that names the file type, such as data:image/png;base64, and then the Base64 text itself. The type comes from the file the browser was given, which for most files means the extension, so a logo.png is labelled image/png and a photo.jpg image/jpeg.

Base64 takes the file three bytes (24 bits) at a time and writes each group as four characters from a 64-letter alphabet: A-Z, a-z, 0-9, + and /. When the last group is short, one or two = signs pad it out. Since it uses only plain letters and symbols, the result survives anywhere text goes, from a CSS file to a JSON field or an HTML email.

You get three versions of the same result. Copy Data URI copies the whole string with its header. Copy Raw Base64 copies only the part after the comma. Copy HTML Tag wraps the data URI in <img src="..." alt="Base64 Image" />, ready to drop into a page.

Base64 length (characters) = 4 × ceil(file size in bytes ÷ 3)
Data URI length            = header length + Base64 length
header examples            : data:image/png;base64, (22 characters), data:image/jpeg;base64, (23)

So the encoded text is always about 33% bigger than the file, plus a header of 22 to 26 characters.

Assumptions and limits

  • One image is encoded at a time. Upload Another Image replaces the current result rather than adding to it.
  • There is no fixed size limit, but very large photos make very long strings: a 5 MB picture becomes about 7 million characters, which can make the text boxes slow to scroll on a phone.
  • The file type in the header is the one your browser reports. A file with a wrong extension can come out with a header that doesn't match the picture, and a file the browser can't identify at all gets the generic data:application/octet-stream, which browsers won't show as an image. Rename it with the correct extension and encode it again.
  • SVG files are Base64-encoded like any other image. That works everywhere, though for small icons a URL-encoded SVG written by hand can be shorter.
  • The ready-made <img> tag uses the placeholder alt text "Base64 Image". Replace it with a short description of the picture before you publish, for accessibility and search.

Worked examples

Embedding a small icon in CSS

A 1.2 KB PNG arrow (1,229 bytes) becomes 1,640 Base64 characters, or a 1,662-character data URI with its header. Paste the data URI into background-image: url("...") and the icon loads with the stylesheet, with no extra file to request.

1,229 ÷ 3 = 409.67 → 410 groups × 4 = 1,640 characters
1,640 + 22 (data:image/png;base64,) = 1,662 characters

Sending a photo inside a JSON request

Many APIs ask for an image field as plain Base64 without the data: header, for example { "image": "/9j/4AAQSkZJRg..." }. Choose the JPG, press Copy Raw Base64 and paste the value between the quotes. A 150 KB photo (153,600 bytes) adds 204,800 characters to the request body.

A logo that must show in an HTML email

Encode the logo and press Copy HTML Tag to get a complete <img> element with the image built in. Some email apps don't display embedded data URIs, so send yourself a test before a full mailing and keep a linked version as a fallback.

Image size to Base64 length, and back

Characters of Base64 for common file sizes, and roughly how big a file a given string holds (header not counted).

Image fileBase64 charactersBase64 stringHolds about
2 KB (2,048 bytes)2,7322,732 characters2 KB
4 KB5,4648,000 characters5.9 KB
8 KB10,92420,000 characters14.6 KB
25 KB34,13640,000 characters29.3 KB
200 KB273,068300,000 characters220 KB
2 MB (2,097,152 bytes)2,796,2043,000,000 characters2.1 MB

How to use the Image to Base64

  1. Upload the image. Click the box and pick a PNG, JPG, WebP, GIF or SVG; the Base64 result appears at once.
  2. Pick the form you need. Data URI for HTML and CSS, Raw Base64 for JSON and APIs, or the HTML <img> tag for a page or email.
  3. Copy and paste it. Press the copy button next to that box, then use Upload Another Image for the next file.

Frequently asked questions

How do I convert an image to a Base64 string?

Click the upload box and choose the image; the result appears in three boxes. Press Copy Data URI if the string goes into an src or url(), or Copy Raw Base64 if a program or API only wants the encoded characters.

What is the difference between a data URI and raw Base64?

A data URI is raw Base64 with a header in front, such as data:image/png;base64, which tells a browser what kind of file follows. Browsers need the header to show the image; most APIs and databases want only the characters after the comma.

When should I use a Base64 image instead of a normal file?

When the image is small, like an icon, a tiny logo or a placeholder, and saving a separate download is worth the extra third in size. Large photos are better kept as files: Base64 makes them bigger, and the browser can't cache them apart from the page or stylesheet they sit in.

Does converting to Base64 reduce image quality?

No. Base64 is an encoding, not compression: it writes the same bytes as text and decoding gives back an identical file. If you need a smaller string, shrink or compress the image first and then encode it.

How do I use the Base64 image in CSS?

Copy the data URI and put it inside url(), for example background-image: url("data:image/png;base64,iVBORw0...");. Keep the quotes, and keep the whole header, because CSS needs the image type to draw it.

Is my image uploaded when I encode it?

No. The encoding runs inside this page with your browser's FileReader, and no copy of the file reaches any server. Screenshots, signatures and product photos that aren't public yet can be encoded without leaving your computer.

This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.