19

I tried displaying a gif animated image inside my HTML code like

<img src="preview.gif" loop=infinite />

With or without the loop tag , it always plays once only.

Any help to make it loop continuously?

Philipp Zettl
  • 177
  • 1
  • 3
  • 17
Bialy
  • 905
  • 2
  • 12
  • 22
  • 1
    Possible duplicate : http://stackoverflow.com/questions/10867789/animated-gif-only-loops-once-in-chrome-and-firefox – rousseauo Nov 09 '16 at 00:20

3 Answers3

43

Looping is encoded into the GIF itself, not the img tag. Open the GIF in an image editor and change the mode to loop, or use a different GIF. The loop attribute is an invalid, deprecated attribute only meant to work when the src is a video.

Andy Ray
  • 30,372
  • 14
  • 101
  • 138
  • `imagemagic` did the job for me simply converting the gif into a loopable version. I followed https://superuser.com/a/888500/250469. – Egel Jan 05 '23 at 02:50
5

As mentioned it is encoded into the GIF but you can change it with tools like photoshop for this:

  • Open your file in Photoshop
  • Go to File and click Save For Web
  • At the very bottom of the save dialog, you will see the Animation section, which should no longer be greyed out
  • Choose forever and save it.
ThisIsWilliam
  • 995
  • 8
  • 10
0

The infinite attribute has no effect on the image. You have to store the infinite on the gif itself in case you generate it on the backend.

Abdulsalam
  • 275
  • 4
  • 6