So that you need an auto-playing looping video with out sound? In common vernacular that is the very that means of the phrase GIF. The phrase has caught round however the picture format itself is historical and out of date. Twitter, for instance, has a “GIF” button that really inserts a <video>
aspect with an MP4 file into your tweet — no .gif
in sight. There are a beguiling quantity of the way to attain the identical end result however one factor is obvious: there’s actually no good purpose to make use of the cumbersome .gif
file format anymore.
<video>
aspect
Use a HTML It’s straightforward to recreate the habits of a GIF utilizing the HTML video aspect.
<video autoplay loop muted playsinline src="https://css-tricks.com/gifs-without-the-gif-the-most-performant-image-and-video-options-right-now/cats.mp4"></video>
With this code the video will play mechanically in a steady loop with no audio. playsinline
implies that cell browsers will play the video the place it’s on the web page slightly than opening in fullscreen.
Whereas the HTML video aspect itself has been supported for a few years, the identical can’t be mentioned for the wide range of video codecs.
Movies are made up of two elements: the container and the video codec. (In case your video accommodates audio then it’s made up of three elements, the third being the audio codec.) Containers can retailer video, audio, subtitles and meta data. The 2 commonest containers for video on the internet are MP4 and WebM. The container is identical because the file sort — if a file ends with a .mp4
extension, meaning it’s utilizing an MP4 container. The file extension doesn’t inform you the codec although. Examples of video codecs generally used on the internet embody VP8, VP9, H.264 and HEVC (H.265). On your video to play on-line, the browser must assist each the video container and the codec.
Browser assist for video is a labyrinthine mess, which is a part of the explanation YouTube embeds are ubiquitous, however that doesn’t work for our use case. Let’s take a look at the video codecs which might be price contemplating.
Containers
- MP4 was initially launched in 2001. It’s supported by all internet browsers and has been for fairly a while.
- WebM was launched in 2010. It really works in all browsers apart from iOS Safari.
Codecs
- The H.264 codec works in all browsers.
- HEVC/H.265, the successor of H.264, is supported by Safari, Edge, and Chrome (as of model 105).
- VP9 is the successor to the VP8 codec. VP9 is supported by all of the browsers that assist WebM.
- The AV1 codec has been supported in Chrome since 2018 and Firefox since 2019. It has not but shipped in Edge or Safari.
An MP4 file utilizing the H.264 codec will work all over the place, however it doesn’t ship the highest quality or the smallest file measurement.
AV1 doesn’t have cross-browser assist but however, launched in 2018, it’s essentially the most fashionable codec round. It’s already getting used, not less than for some movies and platforms, by Netflix, YouTube and Vimeo. AV1 is a royalty-free video codec designed particularly for the web. AV1 was created by the Alliance for Open Media (AOM), a gaggle based by Google, Mozilla, Cisco, Microsoft, Netflix, Amazon, and Intel. Apple is now additionally a member, so it’s secure to imagine all browsers will assist AV1 ultimately. Edge is “nonetheless evaluating choices to assist AVIF and AV1.”
The lately redesigned web site from improvement consultancy Evil Martians is a testomony to the file-size discount that AV1 is able to.