Audio And Video Tags In Html

Audio And Video Tags In Html


1. Audio Tag in HTML

  • The <audio> tag is used to embed sound content in HTML pages, such as music clips or any other audio streams.

  • Within the <audio> tag you can put one or more <source> tags with different audio sources as different browsers support different formats.

  • The browser will automatically pick up the first source it supports.

  • The text between the <audio> and </audio> tags will only be displayed in browsers that do not support the <audio> element.

SYNTAX:

 <audio>
     <source src=”simple.mp3″ type=”audio/mpeg”>
                < source.>
                <source …>
         Your browser does not support the audio tag.
  </audio>

#Supporting Audio Formats in HTML

  • Three types of formats are supported by Audio tags in HTML.

    • MP3 which is an audio format from MPEG (Moving/Motion Pictures Experts Group).

    • WAV which is Waveform Audio File.

    • OGG is An Open container and free audio format.

#MIME Types for HTML Audio Format

Audio FormatMIME Type
mp3audio/mpeg
oggaudio/ogg
wavaudio/wav

#Attributes of Audio tags in HTML

AttributeValueDescription
AutoplayAutoplaySpecifies that the audio will start playing as soon as it is ready
controlscontrolsSpecifies that audio controls should be displayed (such as a play/pause button etc)
looploopSpecifies that the audio will start over again, every time it is finished
mutedmutedSpecifies that the audio output should be muted
srcURLSpecifies the URL of the audio file

Example - 1:

  • The Control attribute of the Audio tag in the HTML.

  • The Control attribute specifies that audio controls should be displayed (such as a play/pause/muted button etc). Wherever we want, we can easily control the audio song.

Example - 2:

Example - 3:

Example - 4:

2. Video Tag in HTML

  • Video tag is used to embed video content in an HTML page, such as a movie, ad or any video clip.

  • The <video> tag contains one or more <source> tags with different video sources.

  • As different browsers support different video formats, the browser will choose the first source it supports.

  • The text between the <video> and </video> tags will only be displayed in browsers that do not support the <video> element.

SYNTAX:

<video>
      <source src=”horse.mp4″ type=”video/mp4″>
        < source.>
        <source …>
        Your browser does not support the audio tag.             
</video>

#Supporting Video Formats in HTML

  • There are three supported video formats in HTML.

    • MP4, WebM, and OGG.

    • We can add them with the type value as shown below.

    • Syntax:

      •     <video>
                   <source src=”horse.mp4″ type=”video/mp4″>
                   <source src=”horse.ogg” type=”video/ogg”>
                   <source src=”horse.webm” type=”video/webm”>
                        Your browser does not support the audio tag.
            </video>
        

#MIME Types for HTML Video Format

Video FormatMIME Type
mp4video/mp4
oggvideo/ogg
webMvideo/webM

#Attributes of Video tag in HTML

AttributeValueDescription
AutoplayAutoplaySpecifies that the video will start playing as soon as it is ready
controlscontrolsSpecifies that video controls should be displayed (such as a play/pause button etc).
heightpixelsSets the height of the video player
looploopSpecifies that the video will start over again, every time it is finished
mutedmutedSpecifies that the audio output of the video should be muted
srcURLSpecifies the URL of the video file
widthpixelsSets the width of the video player

Example - 1:

  • The Control attribute of the Video tag in HTML.

  • Specifies that video controls should be displayed as shown below.

    • Play

    • Pause

    • Seeking

    • Volume

    • Fullscreen toggle

    • Captions/Subtitles (when available)

    • Track (when available)

Example - 2:

Example - 3:

Example - 4: