1.

Explain <audio> in HTML5.

Answer»

Just like <video> we can ALSO embed any kind of audio in a web page using <audio> tag. Any TYPE of sound can be embedded in the web page starting from music to any kind of educational audio. Currently, three types of file formats are supported by <audio> element namely MP3, WAV and OCG.

The important thing to note is that the audio need to be there on your web-server, or in your local drive if testing locally.

The ATTRIBUTES are similar to the video tag and are controls, autoplay, muted, loop.

  • controls will show controls in the media player.
  • autoplay will begin the play as soon as the page is loaded.
  • muted will play the audio without volume. Not recommended
  • loop will play the audio in loop and will run forever.
<!DOCTYPE html> <html> <head>    <title>Audio Demo</title>    <STYLE>        .grid__iframe {            display: grid;            place-content: center;        }    </style> </head> <body>    <div class="grid__iframe">        <audio controls autoplay loop>            <source src="t-rex-roar.mp3" type="audio/mpeg">            <source src="t-rex-roar.ogg" type="audio/ogg">            <p>Your browser doesn't support HTML5 audio.</p>            </audio>    </div> </body> </html>

On the above, you should have a t-rex-roar.mp3 or t-rex-roar.ogg in the same directory as audio.html



Discussion

No Comment Found