-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
What problem are you trying to solve?
To provide alternative text for an animated image sequence, you can use the alt attribute:
<img src="clip.gif" alt="Old man yells at cloud">These days, video is often preferable. The quality is higher, the file size is smaller, and the viewer gains playback controls. You can achieve similar behavior to animated GIFs through a combination of preferences:
<video controls autoplay loop muted playsinline src="clip.mp4"></video>But there isn't a straightforward replacement for the alt attribute. (This has been the most common point of confusion in response to a talk on modern-day GIF-like animations I presented last year.)
Animated GIFs may or may not be declining in popularity, but this need would also apply to more modern short-form video content (the style popularized by TikTok, YouTube Shorts, etc.). These clips are short in length, often with text-based captions that would make them comparable to a GIF or meme in terms of summarization needs.
What solutions exist today?
Some authors incorrectly assume fallback content will work, but that only applies to browsers that don't support <video>.
Another common suggestion is to use captions and subtitles, but those are comparatively time-consuming to generate, and are intended to accompany the media rather than provide a complete alternative.
The most concise and alt-like current solution is to use aria-label (or aria-description):
<video controls autoplay loop muted playsinline
aria-label="Old man yells at cloud"
src="clip.mp4"></video>But this is only reliable when the controls attribute is present. It may also run afoul of automated translation.
You could replace that with aria-labelledby (or aria-describedby):
<video controls autoplay loop muted playsinline
aria-labelledby="video-label"
src="clip.mp4"></video>
<div id="video-label" aria-hidden="true">
Old man yells at cloud
</div>But in addition to requiring the controls attribute as before, you now need a separate element with a corresponding ID, and you'll likely need to manage the extra element's visibility somehow.
The simplest solution may be a figure and caption:
<figure>
<video controls autoplay loop muted playsinline src="clip.mp4"></video>
<figcaption>Old man yells at cloud</figcaption>
</figure>But this introduces two new elements, and may require visibility of the caption to be managed.
Some browsers support video in <img> elements:
<img src="clip.mp4" alt="Old man yells at cloud">But aside from inconsistent support, this requires the author choose between supplying alternative text or providing playback controls.
How would you solve it?
I would include the alt attribute as a feature of <video>:
<video controls autoplay loop muted playsinline
alt="Old man yells at cloud"
src="clip.mp4"></video>For consistency with #6627, this could also apply to individual <source> elements:
<video controls loop muted playsinline>
<source src="clip.mp4" type="video/mp4"
alt="Old man yells at cloud" />
</video>And it would be great for the feature to play nicely with #7954, so there's clarity when alt text applies to poster images versus the media itself.
Anything else?
No response