How to Use HTML5 Video to Create Animated Gifs at Smaller File Sizes

Last Updated on January 6, 2023 by 19 Comments

Editorial Note: We may earn a commission when you visit links on our website.
How to Use HTML5 Video to Create Animated Gifs at Smaller File Sizes
Blog / Resources / How to Use HTML5 Video to Create Animated Gifs at Smaller File Sizes

If you spend even a moderate amount of time online, then youโ€™ll know GIFs are everywhere. Not only are they a great source of humor, but they also make for handy media resources to accompany your content. The problem is, GIFs have a bad reputation due to their large file size, which tends to slow pages down.

Fortunately, GIFs arenโ€™t the only game in town anymore. In fact, there are ways to turn your animations into HTML5 video, which not only runs better, butย also tends to occupy far less space. In this article, weโ€™ll go in-depth about the benefits of the latter over the former, then teach you how to turn your GIFs into HTML5 video, andย show you what to do ifย thatโ€™s not possible. Letโ€™s dig in!

Why You Should Consider Using HTML5 Video Over Regular GIFs

In theory, GIFs and HTML5 video couldnโ€™t be more different. The former is a format that enables you to display both static and animated images, whereas the latterย offers you a way to show embedded videos on a website. Previously, the only way to do this was to use a third-party software such as Flash, since long GIFs would be far too heavy in most cases.

Thatโ€™s where HTML5 video comes to the rescue. Itย takes the greatest issue when it comes to GIFs (large file sizes) and solves it thanks to better optimization from the ground up. However,ย thatโ€™s not all:

  1. Lower file sizes lead to faster loading times. Making sure your site loads quickly is critical to providing a good user experience.
  2. Better customization options. GIFs may be handy, but creating and tweaking them often requires custom software. On the other hand, you can customize the attributes of your HTML5 videos using a few simple lines of code.

As you can see, HTML5 video offers plenty of benefits. However, using it as a substitute for GIFs isnโ€™t ideal for everyone. For example, many mobile browsers disable autoplay due to the impact freely playing media can have on data allowances, leading to a degradation of the userโ€™s experience.

Whatโ€™s more, because HTML5 is still an emerging standard, some browsers implement video differently than others. So if youโ€™re looking to consistently deliver your media to as many devices and browsers as possible, GIFs may still need to be a part of your arsenal. However, if youโ€™re interested in implementing HTML5 video for the reasons listed above, read on to find out how!

How to Turn Your GIFs Into HTML5 Video

Before moving forward, itโ€™s worth noting that HTML5 video isnโ€™t a format in and of itself (while GIF is). Instead, itโ€™s an element that supports video formats, including MP4, WebM, and OGG.

In most cases, youโ€™ll use either MP4 or WebM files, since they tend to be more popular than OGG. The problem is that GIFs have a very particular type of behavior. They usually start playing as soon as they load, loop over and over, and they donโ€™t have sound.

Thatโ€™s where HTML5 attributes come in. Using a few simple lines of code, we can tweak our videos to behave just like GIFs. Take this short animation for example:

At first glance, that might look like a regular GIF, but itโ€™s actually a muted WebM video thatโ€™s been set to autoplay on a loop. To get there, we converted a GIF using the CloudConvert service and embedded it using the following code snippet:

<video autoplay loop muted poster="chaplin.png">
<source type="video/webm" src="chaplin.webm">
</video>

It might look like too much hassle, but we left out the best part. Whileย the original GIF wasย a little over 1MB, its WebM counterpart isย only 95KB. Thatโ€™s a big difference, and even if the same ratio doesnโ€™t hold up in every case, youโ€™re still likely to see notableย improvements in file size by opting for HTML5 video.

Now, letโ€™s get back to the code snippet at hand. Youโ€™ll notice that we used the <video> tags to embed our element. On top of that, we added three particular attributes to simulate the behavior of a GIF โ€“ autoplay, loop, and poster. The first two are self-explanatory, whileย the third specifies an image that will appear as a placeholder while your video is loading (which shouldnโ€™t be an issue for small files).

After specifying which attributes to use, youโ€™ll want to indicate which type of video youโ€™ll embed using one the following codes:

  1. webmย 
  2. mp4
  3. ogg

HTML5 only supports those three video types, so itโ€™s an easy list to remember.

Afterward, youโ€™ll need to specify the location of your video file, using your rootย folder as a reference. For example, if you upload your video to your media library, its location would look something like this:

src="wp-content/uploads/2017/04/chaplin.webm"

Moving on,ย there are a few more attributes that you might want to use for your HTML5 videos. For example, muted can come in handy if your video has sound, and height and width can be necessary if youย want to alter the elementโ€™s size. If you want to include them, all you have to do is add them within your openingย <video>ย tag, like this:

<video autoplay loop muted width="400" height="400">
<source type="video/webm" src="wp-content/uploads/2017/04/chaplin.webm">
</video>

In the example above, our WebM video would play on a loop without sound, and with strict width and height values. Hereโ€™s what that would look like:

Thatโ€™s it in a nutshell! If youโ€™re familiar with HTML, then the process should be a breeze for you. To recap, all you need to do is convert your video or GIF to one of the formats supported by HTML5, thenย embed it using the attributes you want.

Naturally, WordPress makes it easy to embed HTML5 thanks to its built-in code editor, and so does Divi. The themeโ€™s Video module supports both MP4 and WebM videos, and you can assign them the attributes you want through the Custom CSS section. However, be warnedย โ€“ HTML5 video embedded using Diviโ€™s Video module appear with controls by default. That means they wonโ€™t look like GIFs.

To emulate GIFs as closely as possible, youโ€™ll want to paste the requisite HTML5 code by using theย Code module and entering the attributes you want manually. Either way, you have plenty of options at your disposal!

What to Do If You Canโ€™t Use HTML5 Video

Most modern browsers support HTML5 video, but if youโ€™d rather not switch to this method for one reason or another,ย there are still other options.

There are plenty of tools that enable you to optimize your GIFs so they take up less space. One of our favorites isย FileOptimizer, which enables you to optimize dozens of file types, including GIFs:

The File Optimizer program.

The software is both free andย remarkably simple to use. All you have to do is pick which files to optimize and let it work its magic. Naturally, the level of optimization will vary depending on the file you choose, but youโ€™ll generally see good results with GIFs.

If youโ€™d rather use an online service, we recommend checking out ImageOptim. This is a premium tool that can be set up automatically optimize all your images and GIFs, so your pages will load faster:

The Image Optim homepage.

If youโ€™re still on the fence about which option to go with when it comes to GIF optimization, check out this comparison piece we published a while back in which we take a look at several other top-notch options.

Conclusion

In most cases, it makes sense to use HTML5 video over GIFS. After all, you should always make an effort to optimize your pages for the best possible loading times and performance. Plus, it always pays to be ahead of the technological curve, and HTML5 offers plenty of exciting possibilities.

If youโ€™re on board with this idea, hereโ€™s what you need to know to get started:

  1. Convert your GIFs to MP4, WebM or OGG files using a service such as CloudConvert.
  2. Embed your video files using the HTML5 <video> element.
  3. Tweak your HTML5 video using one of the many attributes available, such as autoplay and loop.

Do you think HTML5 video is going to take over GIFs place in the near future? Share your thoughts with us in the comments section below!

Article thumbnail image by Eloku / shutterstock.com

Divi

Want To Build Better WordPress Websites? Start Here! ๐Ÿ‘‡

Take the first step towards a better website.

Get Started
Divi
Premade Layouts

Check Out These Related Posts

Top Features Of Divi Dash For Busy WordPress Agencies

Top Features Of Divi Dash For Busy WordPress Agencies

Posted on October 17, 2024 in Resources

Running a WordPress agency isn’t a walk in the park. It’s a juggling act of keeping clients happy, staying on top of changes, managing your team, building killer websites, and maintaining them โ€” all while trying to stand out in a crowded market. But what if you had a tool to help...

View Full Post
9 Non-Profit Child Themes for Divi

9 Non-Profit Child Themes for Divi

Updated on January 23, 2023 in Resources

There are lots of nonprofit organizations across the globe. Just about every one of them needs a well-designed website to tell their story and receive donations to help their causes. Divi is an excellent theme for nonprofits such as charities. Fortunately, you donโ€™t have to start from scratch for...

View Full Post

19 Comments

  1. mmm… in Safari dont see the videos…

  2. Can’t see anything on Chrome iPhone 6 ๐Ÿ™

    Could you try uploading a mp4 instead of a webm please? Just to test whether this is a movie format issue.

    Thanks,
    Guido

  3. What’s the best, preferably free, tool for converting videos to GIFs?

  4. “Do you think HTML5 video is going to take over GIFs place in the near future? Share your thoughts with us in the comments section below!”

    Not any time soon.
    We need a strong standard, not a Apples vs, Chrome, vs Whatever. Just look at the mess of trying to set Favicons! Now add GIFs vs HTML5 Video and it only adds to this debacle.

    See comments above from other users experiences)

  5. Unfortunately, because of the abuse of autoplay, subbing video for a gif isn’t even a good desktop experience. A lot of people block autoplay. I do it because I’m sick of the constant barrage of video when I’m trying to read the morning news – reading is so much faster than listening. Html5 video can’t replace a gif if you want your image to be seen.

  6. I had small videos I wanted to use on a client’s WooCommerce store as part of the product gallery. I couldn’t figure out how to add a video to the gallery so converted the video into a Gif, which worked fine. It would be nice if WooCommerce allowed videos as part of their product image galleries.

    • Hi Bob! Thanks for your input. ๐Ÿ™‚

  7. Can’t see any video or animation in Safari on MacBook Pro either. Just blank space ๐Ÿ™

  8. Thank’s for this fine tutorial. Alberto

    • You’re welcome, Alberto. ๐Ÿ™‚

  9. The second example plays on my Galaxy s7 edge but the first one is just an image.

  10. hahahah looks like the other commenters beat me to it. It’s like this whole guide is only for the people who are designing for a desktop only experience….. cricket cricket…

  11. WebM not suported by Apple Safari …

  12. No videos on iPad Pro

  13. At my iPhone 6 there is also no video visible. Only a blank screen…

  14. No video on iPhone 6s +

  15. You can’t autoplay video on mobiles though.

  16. Your samples are not visible on iphone7. All I see is the arrow icon.

Leave A Reply

Comments are reviewed and must adhere to our comments policy.

Get Started With Divi