Can we use an alt attribute with the <video> tag?

Question

The text content of <video> tags seems to behave in the same way as the alternative text for the <img> tag. For consistency, can we use an alt attribute with the <video> tag instead?

Answer

This is a great observation! We can not use the <alt> attribute within the opening <video> tag. While this may seem inconsistent, this is actually by design as we might want our video element to contain some fallback options. For example, if the video doesn’t load we might want to display a link to another video that does. As attributes cannot contain markup, this scenario would not be possible with alt attributes alone.

If this fallback handling gives the developer more control, you might be wondering why the <img> tag doesn’t follow suit. The answer to this involves backwards-compatibility troubles.

if the alt attribute cant be added to tag, in the video not supported area, can you add the alt link to the video?

The <video> element in HTML doesn’t have an alt attribute like the <img> element does. However, if you want to provide an alternative content or link for situations where the video is not supported, you can use the <a> (anchor) element to wrap the video. This way, you can include a link or alternative content within the anchor element.

<a href="alternative-link.html">
  <video controls width="400" height="300">
    <source src="video.mp4" type="video/mp4">
    Your browser does not support the video tag.
  </video>
</a>

In this example, if the browser doesn’t support the <video> tag or encounters issues loading the video, it will display the content inside the <a> tag, which is a link to an alternative page (alternative-link.html in this case). You can replace “alternative-link.html” with the actual link you want to provide as an alternative.