HTML Audio/Video - 4 Tags and its Attributes (Reference)

Tech:
Html
Since:
1 year ago
Views:
5

The audio and video tags are used to embed audio and video files in html. The audio and video tags can have attributes like autoplay, controls, loop, muted, preload, src, and type.

Audio/Video tags:

<audio>

Defines sound content. Browser will choose the first best source. Attributes - autoplay, controls, loop, muted, preload, src.

<audio controls>
  <source src="URL" type="audio/ogg" />
  <source src="URL" type="audio/mpeg" />
  Your browser does not support
</audio>

<video>

Defines a video or movie. Attributes - autoplay, controls, height, loop, muted, poster, preload, src, width.

<video width="320" height="240" controls>
  <source src="URL" type="video/mp4" />
  <source src="URL" type="video/ogg" />
  Your browser does not support
</video>

<source>

Defines multiple media resources for media elements. Used inside video, audio, picture tags.

<audio controls>
  <source src="URL" type="audio/ogg" />
  <source src="URL" type="audio/mpeg" />
  Your browser does not support
</audio>

<picture>
  <source media="(min-width:650px)" srcset="URL_3" />
  <source media="(min-width:465px)" srcset="URL_2" />
  <img src="URL_1" alt="Flowers" style="width:auto;" />
</picture>

<track>

Defines text tracks for media elements. Basically subtitles. Attributes - default, kind, label, src, srclang.

<video width="320" height="240" controls>
  <source src="URL" type="video/mp4" />
  <track src="URL" kind="subtitles" srclang="en" label="English" />
  <track src="URL" kind="subtitles" srclang="no" label="German" />
</video>