Since the release of HTML5, audios can be added to webpages using the “audio” tag. Previously audios could be only played on webpages using web plugins like Flash. The “audio” tag is an inline element which is used to embed sound files into a web page. It is a very useful tag if you want to add audio such as songs, interviews etc on your webpage.
The first versions of different browsers that support the “audio” tag are :
The various attributes that can be used with the “audio” tag are listed below :
- Controls : Designates what controls to display with the audio player.
- Autoplay : Designates that the audio file will play immediately after it loads controls.
- Loop : Designates that the audio file should continuously repeat.
- src : Designates the URL of the audio file.
- muted : Designates that the audio file should be muted.
Supported Formats :
Three formats mp3, ogg, wav are supported by HTML5. The support for each format by different browsers is given below :
Adding audio on Webpage :
Code Explanation :
- The controls attribute is used to add audio controls such as play, pause, and volume.
- The “source” element is used to specify the audio files which the browser may use. The first recognised format is used by the browser.
Autoplaying audio on a Webpage :
The autoplay attribute is used to automatically begin playback of the audio file whenever the URL of the webpage is loaded.
Adding muted audio file on a Webpage :
The muted attribute specifies that the audio should be muted on the webpage.
Adding audio using the source element :
The source element can be used to add audio files to a webpage. The src attribute is used to specify the source of the file specified.
Adding audio with multiple sources :
Multiple sources of an audio is specified so that if the browser is unable to play the first source then it will automatically jump to the second source and try to play it.
Adding audio using the “Embed” tag :
Adding audios on a webpage using the “embed” tag is an old technique.This method does work but is comparatively less efficient than the other methods.
The user must have a plugin like MIDI or QuickTime because the embed tag requires a plugin for support.
- HTML | DOM Audio Object
- YouTube Media/Audio Download using Python | pafy
- HTML5 | <aside> Tag
- HTML5 | rt Tag
- HTML5 | rp Tag
- HTML5 | fieldset Tag
- HTML5 | mark Tag
- HTML5 | figcaption Tag
- HTML5 | <ruby> Tag
- HTML5 | figure Tag
- HTML5 | Introduction
- HTML5 | <meter> Tag
- HTML5 | <details> tag
- HTML5 | <dialog> Tag
- HTML5 | Semantics
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.