data:image/gif Images Are Not Animated by Default
You are encountering a behavior that trips up many frontend developers: embedding an animated GIF directly into HTML using the data: URI scheme results in only the first frame being displayed. This is not a browser bug, nor is it a configuration error on your part. It is a fundamental limitation of how modern browsers handle inline image resources versus external network requests.
When you serve an image from a URL like https://example.com/animation.gif, the browser fetches the entire file and decodes the animation frames as soon as they become available. However, when using a data:image/gif;base64,... string, the resource is treated differently by the rendering engine.
Why the Animation Fails in Data URIs
The core issue lies in the optimization strategies browsers employ to manage memory and performance. When an image is loaded from a network URL, the browser can stream the data as it arrives. It begins decoding frames immediately and renders them sequentially.
In contrast, a data: URI requires the entire base64 string to be fetched (or typed) into memory before the browser can even begin parsing it. To avoid allocating significant RAM for large images, many browsers implement a lazy-loading heuristic for inline data URIs. They intentionally render only the first frame of an image immediately. The animation frames are ignored unless specific conditions are met.
This behavior is consistent across major browsers like Chrome and Edge. It is not specific to your environment or version. If you have verified this on both Chrome and Microsoft Edge with the same base64 string, the result is expected.
How to Force Animation in Data URIs
If you must embed an animated GIF using a data: URIâfor example, to avoid CORS issues or to bundle assets directly into your JavaScript/HTML without HTTP requestsâyou can force the browser to decode the animation by triggering a reflow or forcing a layout update.
The most reliable method is to append a small, invisible transparent 1x1 pixel GIF image immediately after the base64 string you want to animate. This forces the browser to treat the entire sequence as part of a single resource stream rather than stopping at the first frame.
Here is how you modify your HTML:
<!-- Original non-animated data URI -->
<img src='data:image/gif;base64,R0lGODlhEAAQAMQAAORiAO0cJAAAAAAAAAAAACH5BAEAAAUALAAAAADIAMgAAAP+WLrc/jDKSau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd94ru987//AoHBILBqPyKRyyWw6n9CodEqtWq/YrHbL7Xq/4LB4TC6bz+i0es1uu9/wuHxOr9vv+Lx+z+/7/4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3uLm6u7y9vr/AwcLDxMXGx8jJysvMzc7P0NHS09TV1tfY2drb3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