★ Every tool runs 100% in your browser. Nothing is uploaded, ever

Convert Formats

GIF to Base64 Converter

This free GIF to Base64 converter runs in your browser. Drop a GIF in and it hands you the same file as text: the full data URI, the raw Base64 string, and the string already wrapped as an HTML img tag, a CSS background rule and a JSON value, each with a copy button. Because a Base64 string is always a third bigger than the file it came from, the readout measures your actual file first and tells you plainly whether inlining it is a good idea, before you paste a million characters into a page.

Two things are worth knowing before you start. First, the encoding is lossless in the strictest sense: it re-writes the file's bytes as text, so every frame, delay and loop of an animated GIF survives, and the preview below plays from the string itself so you can watch it work. Second, the real format is read from the file's own bytes, not its name: a PNG saved as .gif is encoded with the image/png prefix it actually needs, and the readout says so.

Drop a GIF here, or paste one from your clipboard

The built-in sample GIF below is already encoded, so you can see the strings and the readout first.

Your file, measured, then its strings

Honest limits, checked before anything is encoded: files up to 10 MB. The encoding itself has no size limit, but a 10 MB file's string runs past 13 million characters, and no string that size belongs inside a web page. The verdict above uses this page's stated thresholds: up to 50 KB of GIF, inlining is reasonable; 50 KB to 300 KB, inline with care; over 300 KB, too heavy to inline.

How to convert a GIF to Base64

  1. Load the GIF. Drop it on the box above, paste it, or pick a file, or look at the built-in sample first. The facts panel states the file's real format, read from its own first bytes, plus its size and, for a GIF, its dimensions, frame count and looping.
  2. Read the verdict. The readout states the string's exact length and the overhead percentage for your file, and gives a plain verdict: small enough to inline, inline with care, or too heavy to inline. That verdict is computed from your file, not copied from a rule of thumb.
  3. Copy the form you need. The data URI for most jobs, the raw string for an API or a template that adds its own prefix, or the finished img tag, CSS rule or JSON value. Each has its own copy button and character count.
  4. Or download the string. The download saves the full data URI as a plain text file, which is the safer route for a long string: no risk of a chat window or a form field quietly cutting it in half.

What Base64 does to the size, exactly

Base64 writes binary data in a 64-character alphabet, 6 bits at a time, so every 3 bytes of a file become 4 characters of text. The encoded length is not an estimate: it is 4 x ceil(bytes / 3), a third more than the file, every time. The data URI form adds the prefix data:image/gif;base64, on top, 22 characters for a GIF. A 30 KB spinner becomes a string of about 40,000 characters; a 1 MB GIF becomes about 1.4 million. Nothing is compressed and nothing is lost in either direction: decode the string and you have your file back, byte for byte.

The size is only half the cost. An inlined GIF cannot be cached separately: it is part of the HTML, CSS or JSON file that holds it, so a returning visitor downloads those characters again every time that file is fetched, and the browser cannot start showing the image until it has parsed its way through the string. A hosted GIF file, by contrast, is downloaded once and reused from the cache on every page that references it. That is the real trade behind the verdict thresholds on this page: inlining buys you one fewer request, and charges you a third more bytes, paid again on every uncached load.

When inlining a GIF makes sense

When it does not

Base64 GIFs in email: the honest version

Embedding a GIF in an HTML email as a data URI is the use case this conversion is most often sold on, and it is the one to be careful with. Support for data URI images across email clients is inconsistent: many webmail and mobile clients render them, but some widely used desktop clients, Outlook on Windows among them historically, do not render data URI images at all, and a recipient on such a client sees a blank box where your animation should be. The string also inflates the email's HTML by a third more than the GIF, and some sending systems clip long messages. So: use a data URI in email only for a small GIF, only after sending yourself a test in the clients your audience actually uses, and keep a hosted image as the plan anywhere the animation carries the message.

How to use each string

In HTML

The data URI goes where the file's address would go. The img tag this tool hands you looks like this, with your GIF's string where the dots are:

<img src="data:image/gif;base64,R0lGODlh..." alt="">

The opening R0lGODlh is not a coincidence: every GIF89a file starts with the same six bytes, so every GIF data URI starts with those same characters (a GIF87a starts R0lGODdh). If your string starts with anything else, it is not a GIF, whatever its name said.

In CSS

.spinner { background-image: url("data:image/gif;base64,R0lGODlh..."); }

The rule this tool hands you is the background-image line on its own, ready to drop into your own selector. Keep the quotes: a Base64 string can contain characters a browser would rather see inside them.

In JSON and JavaScript

{ "image": "data:image/gif;base64,R0lGODlh..." }

A data URI is a plain string, so it drops into a JSON value, a JavaScript variable or a template without escaping: the Base64 alphabet contains no quotes and no backslashes. That is one reason the format survives in configs and APIs.

Doing it in code instead

If the GIFs keep coming, encode them where your code already is. The same three lines exist in every stack:

const bytes = await (await fetch('spinner.gif')).arrayBuffer(); let bin = ''; new Uint8Array(bytes).forEach(b => { bin += String.fromCharCode(b); }); const dataUri = 'data:image/gif;base64,' + btoa(bin);

import base64 data = open('spinner.gif', 'rb').read() data_uri = 'data:image/gif;base64,' + base64.b64encode(data).decode()

$dataUri = 'data:image/gif;base64,' . base64_encode(file_get_contents('spinner.gif'));

One warning that applies to the JavaScript version: building the binary string byte by byte is fine for small GIFs, but for a file of several MB, convert it in chunks, as this page does, or use a library that does. The encoding is the same either way; only the memory manners differ.

Common mistakes

A worked example, with real numbers

These figures come from encoding this page's built-in sample file through this tool. The sample is a fixed GIF file, the bouncing-ball scene the MotionGIF tools share (320 x 200 px, 12 frames, looping forever), so its bytes are the same in every browser and the same numbers come out every time.

Every file you load reports its own real numbers the same way, so your GIF's verdict is never a guess from this example: the readout states its bytes, its string lengths and its overhead before you copy anything. If yours comes back too heavy, the GIF Compressor can take the GIF down first, and the smaller file will encode to a shorter string.

Questions people ask about turning a GIF into Base64

Do animated GIFs still animate after Base64 conversion?

Yes. Base64 does not change the GIF, it re-writes the same bytes as text: every 3 bytes of the file become 4 characters. When a browser decodes the string it gets your file back byte for byte, with every frame, every frame delay and the loop count intact, so the animation plays exactly as it did. The preview on this page is playing from the data URI itself, which is the proof: if the string were damaged, the animation would be too.

Is there a file size limit for Base64 encoding?

The encoding itself has no size limit: any file can be turned into a string, and the string is always exactly 4 x ceil(bytes / 3) characters. This tool accepts files up to 10 MB, because past that the string runs past 13 million characters and is far too heavy to inline anywhere. The practical limit is much lower: this page calls a GIF small enough to inline up to 50 KB, worth care up to 300 KB, and too heavy to inline above that.

How do I use the Base64 string in HTML?

Paste the data URI form where you would normally put the file's address, as the src of an img tag. The browser reads the image straight out of the attribute, so no separate file is requested. The tool above hands you the finished img tag with your GIF already inside it, ready to paste. Keep the whole prefix: an img tag whose src is the raw string without data:image/gif;base64, in front of it will not render.

Can I use Base64 GIFs in CSS?

Yes. A Base64 GIF goes in a CSS rule as the address inside background-image: url(...), with the full data URI between the brackets, and the tool above hands you that rule ready to paste. Remember the string then lives inside your CSS file, so the CSS grows by the string's full length, and the image is cached only as part of that file, never on its own. That trade is worth it for a small spinner or icon, and rarely for anything bigger.

How do I turn a GIF into Base64?

Drop the GIF on the box at the top of this page, or pick it, or paste it. The conversion happens in your browser the moment the file lands: you get the raw Base64 string, the full data URI, and the same string already wrapped as an HTML img tag, a CSS rule and a JSON value, each with a copy button, plus a download of the data URI as a text file. The readout above the strings tells you the file's size, the string's length and whether inlining this particular GIF is a good idea.

Are my GIF files uploaded anywhere during conversion?

No. The file is read and encoded inside your browser tab, by your own device, and nothing is sent to a server at any point. That is also why there is no account, no queue and no watermark, and why the tool works offline once the page has loaded.

Related tools

Encoding a GIF is usually the last step of a longer job. These MotionGIF tools cover the steps that tend to come before it:

Browse all MotionGIF tools →