Image tools
Image to Base64 converter for data URIs, HTML and CSS
Convert an image to Base64 text that you can paste into HTML, CSS or code. Choose a PNG, JPEG, GIF, WebP, SVG or other image file, then get a data URI, raw Base64, an HTML img tag or a CSS background. The encoding runs in your browser and keeps every byte of the file.
Processed on your device
Image file
Select a local image to encode without changing it.
No image selected
A preview will appear after encoding, if your browser supports the image.
Original bytes and metadata are preserved. This tool does not resize, compress, strip metadata or sanitize your image.
Choose an image and output format, then encode or download.
Encoded output
Your result will appear here.
Media type is identified from file headers, not the filename.
HTML output has an empty alt attribute. Add meaningful alternative text when placing it on your page.
How to convert an image to Base64
- Choose an image file
Select Choose image and pick one file. Check its name and size beside Replace image.
- Select the Base64 format
Open Output format. Pick Data URI, Raw Base64, HTML image or CSS background for your destination.
- Save or copy the encoded text
Select Download text to save a .txt file directly. To inspect or copy it first, select Encode image, then Copy output.
Select Choose image and pick one file from your device. The line next to the button shows its name and file size. Open Output format, pick Data URI, Raw Base64, HTML image or CSS background. Select Encode image to inspect the text, or Download text to save it directly.
The encoded text fills the Output text box, and the line above it gives the original size, the number of output characters and how much larger the text is. A preview of the original image appears under the chooser when your browser can display the format. If you pick another output format after encoding, the image is encoded again in that format. Cancel stops a run, and Reset clears the image and the output and sets the format back to Data URI.
The four output formats
Data URI gives data:, the media type, ;base64, and then the encoded bytes, for example data:image/png;base64,iVBORw0KGgo. Paste it where a URL is accepted, such as the src of an image or a CSS url(). Raw Base64 is the encoded string alone, for an API field or a settings file that expects only the bytes.
HTML image puts the data URI in an img element with an empty alt attribute. Write alt text that describes the picture before you publish it. CSS background gives one declaration, background-image: url(...);, to place inside a CSS rule.
For a one-pixel PNG of 68 bytes, raw Base64 has 92 characters, the data URI 114, the HTML image 133 and the CSS background 140. The wrapper adds the same number of characters to any PNG, whatever its size, so for a large file the Base64 itself is nearly all of the output.
Why Base64 makes an image larger
Base64 turns every group of 3 bytes into 4 characters from a 64-character alphabet, so the text is about 33 percent larger than the file. A 100 KB image becomes 133,336 characters of raw Base64, and a 1 MB image becomes 1,333,336. When the byte count is not a multiple of 3, the last group ends with one or two = signs, so a file of 1 byte still gives 4 characters.
Base64 is an encoding: it does not compress the image, and anyone who has the text can decode it, so it hides nothing. An embedded image also adds all of that text to your HTML page or stylesheet. Data URIs are most practical for small images such as icons, logos and simple graphics. For a large photo, compress or resize it first, or link to a separate image file instead.
What stays the same in the encoded file
The tool reads the original bytes and encodes them without decoding the image or saving it again. Metadata such as EXIF and GPS tags, color profiles and animation stay in the encoded text exactly as they are in the file. The tool does not resize, compress, strip metadata or clean your image, so remove a location tag first if you do not want to share it.
The media type in the data URI comes from the file header, not the file name, so a JPEG saved as photo.png is labeled image/jpeg. The tool recognizes PNG, JPEG, GIF, WebP, BMP, TIFF, AVIF, HEIC, SVG and ICO headers. A file with any other header gets application/octet-stream, which may not display as an image, although the raw Base64 still holds every byte. A known header does not prove that the rest of the file is valid.
Limits
The tool encodes one image file at a time, in one direction. It does not fetch an image from a URL or read one pasted from the clipboard, so save the image as a file first. To turn Base64 back into a file, use the Base64 encoder and decoder.
There is no size limit set by the tool, but the file and its text must fit in your browser's memory. When the output is longer than 1,000,000 characters, the text box shows only the first 1,000,000 so the page stays responsive. Copy output and Download text still hold every character.
The preview depends on your browser, so a HEIC or TIFF file can encode without a preview. An SVG preview is shown as an image, which blocks its scripts and external files, but the encoded SVG is not changed or cleaned. The page that uses the result must support the format and allow data images.
Questions
How do I convert a picture to Base64?
Select Choose image and pick the picture. Choose Data URI for use in a web page or Raw Base64 for the encoded string alone, then select Encode image. Select Copy output to put the text on the clipboard, or Download text to save it. Changing the format afterwards encodes the picture again.
What does == mean at the end of Base64?
It is padding. Base64 encodes 3 bytes as 4 characters, so when a file's byte count is not a multiple of 3, the last group is short. One leftover byte ends with ==, and two leftover bytes end with a single =. The padding keeps the text length a multiple of 4 characters.
What is a Base64 image?
It is an image file written as text with the 64 Base64 characters. As a data URI, the text starts with data:, the media type and ;base64, so a browser can show it from an img element or a CSS background with no separate image request. The browser decodes it back to the original bytes.
How do I convert a PNG image to Base64?
Choose the PNG and select Encode image with Data URI selected. The tool reads the PNG header, so the result starts with data:image/png;base64, even if the file name has another extension. The text is about a third larger than the PNG, and transparency and metadata stay as they are.
Is Base64 encoding safe for images?
Base64 is safe to use for images, but it keeps nothing secret. There is no key, and anyone who has the text can decode it to the original file, including its EXIF data. Check the metadata before you publish a photo, and treat an encoded SVG from an unknown source like the original SVG file.
How do I show a Base64 image in HTML?
Choose HTML image as the Output format and select Encode image. The result is an img element whose src is the data URI, ready to paste into your HTML. Fill in the empty alt attribute with a short description of the picture. The page's content security policy must allow data images.
How do I open a Base64 image?
This tool only encodes. To open Base64 text as a file, use the Base64 encoder and decoder, choose Decode and paste the raw Base64 or the data URI. Download the result and give it the extension of the original format, such as .png, so that your image viewer can open it.
Does my image leave this device?
No. The image is read and encoded in your browser on this device, and the tool does not upload, log or store it. The text only leaves the page when you copy or download it. Cancel, Reset, choosing another file and leaving the page each clear the result from the page.
Related tools
- Compress an image: make a JPEG, PNG, WebP or AVIF file smaller before you encode it.
- Resize an image: set the pixel size you will display before you embed it.
- View and remove photo metadata: take out EXIF and GPS tags that Base64 would keep.
- Optimize SVG markup: shrink an SVG file before you turn it into a data URI.