Table of Contents
Using HTML Element
The advantages of pictures: WebP and AVIF
Using animation AVIF
Home Web Front-end CSS Tutorial GIFs Without the .gif: The Most Performant Image and Video Options Right Now

GIFs Without the .gif: The Most Performant Image and Video Options Right Now

Mar 10, 2025 am 09:46 AM

Say goodbye to the GIF era! Best practices for efficient web animation

GIFs Without the .gif: The Most Performant Image and Video Options Right Now

Still using outdated GIF animations? In fact, there are more efficient and better performance alternatives nowadays! This article will explore in-depth how to achieve smooth looping video animations with more modern techniques, taking into account browser compatibility and user experience.

Using HTML <video></video> Element

Use the <video></video> elements of HTML to easily reproduce the GIF animation effect:

<video autoplay="" loop="" muted="" playsinline="" src="cats.mp4"></video>
Copy after login
Copy after login

This code implements automatic playback, loop playback, mute and inline playback (avoid full screen playback). However, the compatibility issues of video formats cannot be ignored.

Video files are composed of containers and video codecs (including audio, and audio codecs are also included). Common video container formats are MP4 and WebM. The browser needs to support both containers and codecs to play videos.

The browser supports video formats in a variety of complex and diverse way, which is one of the reasons why YouTube embedded videos are so popular. Let's see what video formats are worth considering:

Container format:

  • MP4: Since its release in 2001, it has been supported by almost all browsers.
  • WebM: Released in 2010, except for iOS Safari, and other browsers support it.

Codecode:

  • H.264: All browsers support it.
  • HEVC/H.265: The successor of H.264, supported by Safari, Edge and Chrome (version 105 and above).
  • VP9: The successor of VP8, supported by all browsers that support WebM.
  • AV1: Chrome has been supported since 2018, Firefox has been supported since 2019, and Edge and Safari have not yet been supported.

MP4 files with H.264 encoding have the best compatibility, but the quality and file size are not the best. Although the compatibility of AV1 is not yet perfect, as the latest codec, its efficiency and quality are extremely high. Platforms such as Netflix, YouTube and Vimeo are already used in some videos.

In order to take into account the old and new browsers, you can use multiple <source></source> elements, prioritize the designation of the ideal source file, and then add alternatives in turn:

<video autoplay="" loop="" muted="" playsinline="">
  <source src="cats.webm" type="video/webm; codecs='vp9'">
  <source src="cats.mp4" type="video/mp4; codecs='avc1.42E01E'">
</source></source></video>
Copy after login
Copy after login

If you need to use multiple MP4 files with different codecs, you need to use complex codecs parameters.

Most video editing software does not support direct export of AV1 or WebM formats, and requires the conversion using tools such as FFmpeg:

ffmpeg -i yourSourceFile.mov -map_metadata -1 -c:a libopus -c:v librav1e -qp 80 -tile-columns 2 -tile-rows 2 -pix_fmt yuv420p -movflags +faststart -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" videoTitle.mp4
Copy after login
Copy after login

Convert GIF to MP4:

ffmpeg -i cats.gif -map_metadata -1 -an opus -c:v librav1e -qp 80 -tile-columns 2 -tile-rows 2 -pix_fmt yuv420p -movflags +faststart -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" cats.mp4
Copy after login

Using the video as the background and superimposing other elements requires CSS positioning:

.video-parent {
  position: relative;
  width: 100vw;
  height: 100vh;
}

.video-parent video {
  object-fit: cover;
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
}
Copy after login
One disadvantage of

<video></video> elements is that they prevent the screen from hibernating.

The advantages of pictures: WebP and AVIF

Using animated WebP or AVIF image formats has the following advantages:

  • Different animation images can be used for different screen sizes or theme modes (such as dark mode).
  • Native support for lazy loading: <img src="/static/imghw/default1.png" data-src="https://img.php.cn/" class="lazy" alt="GIFs Without the .gif: The Most Performant Image and Video Options Right Now ">
  • Easier to use as background image: background-image: url("coolbackground.webp");

It can be used<img src="/static/imghw/default1.png" data-src="https://img.php.cn/" class="lazy" alt="GIFs Without the .gif: The Most Performant Image and Video Options Right Now ">

(The form is omitted, the same as the original form)

Using animation AVIF

AVIF format (released in 2019) is one of the best image formats at present, converting GIF to AVIF can reduce the number of bytes by more than 90%:

<video autoplay="" loop="" muted="" playsinline="" src="cats.mp4"></video>
Copy after login
Copy after login

AVIF is based on AV1 video codec and supports static and animation images.

(The form is omitted, the same as the original form)

Using<img src="/static/imghw/default1.png" data-src="https://img.php.cn/" class="lazy" alt="GIFs Without the .gif: The Most Performant Image and Video Options Right Now "> This can achieve effects such as video background or border images in Safari:

<video autoplay="" loop="" muted="" playsinline="">
  <source src="cats.webm" type="video/webm; codecs='vp9'">
  <source src="cats.mp4" type="video/mp4; codecs='avc1.42E01E'">
</source></source></video>
Copy after login
Copy after login
Safari claims this feature has performance advantages, but Chrome has made it clear that it will not support it.

Respect user preferences

Video elements automatically respect the user's autoplay settings and "reduce animation" settings.

Check progressive enhancement

Support for AVIF and WebP formats can be turned off using Chrome DevTools' "Rendering" tab to test code compatibility.

Lottie animation library

Lottie is an open source animation library that exports animation data (JSON files) from After Effects and renders it to a web page. It supports multiple platforms and provides flexible control options such as playback, pause, reverse playback, etc.

ffmpeg -i yourSourceFile.mov -map_metadata -1 -c:a libopus -c:v librav1e -qp 80 -tile-columns 2 -tile-rows 2 -pix_fmt yuv420p -movflags +faststart -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" videoTitle.mp4
Copy after login
Copy after login
Lottie's performance depends on the library size and JSON file size and the number of DOM elements generated.

Conclusion: There is no absolute best solution, and the choice needs to be weighed based on specific needs and project conditions.

The above is the detailed content of GIFs Without the .gif: The Most Performant Image and Video Options Right Now. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Working With GraphQL Caching Working With GraphQL Caching Mar 19, 2025 am 09:36 AM

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

Making Your First Custom Svelte Transition Making Your First Custom Svelte Transition Mar 15, 2025 am 11:08 AM

The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions.

Show, Don't Tell Show, Don't Tell Mar 16, 2025 am 11:49 AM

How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

What the Heck Are npm Commands? What the Heck Are npm Commands? Mar 15, 2025 am 11:36 AM

npm commands run various tasks for you, either as a one-off or a continuously running process for things like starting a server or compiling code.

How do you use CSS to create text effects, such as text shadows and gradients? How do you use CSS to create text effects, such as text shadows and gradients? Mar 14, 2025 am 11:10 AM

The article discusses using CSS for text effects like shadows and gradients, optimizing them for performance, and enhancing user experience. It also lists resources for beginners.(159 characters)

Creating Your Own Bragdoc With Eleventy Creating Your Own Bragdoc With Eleventy Mar 18, 2025 am 11:23 AM

No matter what stage you’re at as a developer, the tasks we complete—whether big or small—make a huge impact in our personal and professional growth.

Let's use (X, X, X, X) for talking about specificity Let's use (X, X, X, X) for talking about specificity Mar 24, 2025 am 10:37 AM

I was just chatting with Eric Meyer the other day and I remembered an Eric Meyer story from my formative years. I wrote a blog post about CSS specificity, and

See all articles